Comments (9)
Ah good to know! 👍 I can send a PR tomorrow if @d4rekanguok haven't fixed it already.
from netlify-cms-widgets.
Thank you for reporting in, I'll try to reproduce the error & see if I can fix it.
from netlify-cms-widgets.
It can be reproduced here:
https://custom-widgets.netlify.com/#/collections/posts/new
The componentDidMount
method does not trigger on history changes, one solution could be to replace it with:
public componentWillReceiveProps(nextProps: WidgetProps) {
const { value, field, onChange } = nextProps
if (value) return
// else generate id as previous in didMount...
}
I'm not really familar with lifecycle methods but I've tested it and it seems fine and fixes the bug. Or do you think there are some better solution?
from netlify-cms-widgets.
Yeah, you are not leaving the page, so didMount
will not run again. componentWillReceiveProps
is deprecated (https://reactjs.org/docs/react-component.html#updating)
The component would be better off using constructor
and https://reactjs.org/docs/react-component.html#componentdidupdate
to see if the value turned empty to create a new ID
from netlify-cms-widgets.
@gurkodil please do!
from netlify-cms-widgets.
The widget worked as expected now, thanks again @gurkodil @laurenskling! Published in @ncwidgets/[email protected]
from netlify-cms-widgets.
I'm still seeing componentDidMount
after installing 0.5.1
🤔
from netlify-cms-widgets.
@laurenskling ugh, sorry that the issue still persists after the update. Could it be a cache issue on your side? I've checked the built js file here, the changes have been applied:
// https://unpkg.com/@ncwidgets/[email protected]/dist/control.js
class Control extends React.Component {
constructor(props) {
super(props);
if (props.value)
return;
this.generateId();
}
generateId() {
const { field, onChange } = this.props;
const usePrefix = field.get('prefix');
const useTimestamp = field.get('timestamp');
const prefix = usePrefix ? usePrefix + '-' : '';
const timestamp = useTimestamp ? Date.now() + '-' : '';
const id = prefix + timestamp + shortid_1.default();
onChange(id);
}
componentDidUpdate() {
if (this.props.value)
return;
this.generateId();
}
render() {
const { forID, classNameWrapper, setActiveStyle, setInactiveStyle, value, } = this.props;
return (React.createElement("input", { type: 'text', className: classNameWrapper, style: {
color: '#cdcdcd',
}, value: value || '', id: forID, onFocus: setActiveStyle, onBlur: setInactiveStyle, disabled: true }));
}
}
exports.Control = Control;
I've also tried the component in a codesandbox, and the component does generate a new id when using 'Publish and create new' option : https://codesandbox.io/s/netlify-cms-app-example-h5n43?fontsize=14&hidenavigation=1&theme=dark
from netlify-cms-widgets.
Just installed it correctly! Must have been some caching issue https://shouldiblamecaching.com/
Thanks so much!
from netlify-cms-widgets.
Related Issues (20)
- Inline widget HOT 14
- Re-order widget – i18n ? HOT 1
- Adding widget script hides existing relations in CMS HOT 2
- Duplicating an item doesn't generate new ID HOT 4
- @ncwidgets/file-relation not working on self assignment HOT 2
- Need test + CI
- File location for relation widget HOT 13
- File Location Widget is broken HOT 2
- (file-relation) Support simple list (string only) HOT 1
- Last updated widget
- [netlify-cms] Add ncw-reorder HOT 2
- unselect an item from a parent optional field HOT 3
- hidden option for ncw-id widget HOT 3
- Display_fields accept one field only HOT 10
- file-relation update
- Form builder widget
- Is it possible to use id widget as js deliver sript?
- Data table widget
- S3 media library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netlify-cms-widgets.