-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: value property #16
Conversation
I am getting error:
This solution is not suitable? this.refs.tags.el.val('value').trigger('change'); |
74d7d62
to
ea1f431
Compare
You solution, unfortunately does't work (I had errors after uglify code and also receve internal select2 error). But after this patch - all right. And I'll try to fix warning |
@@ -53,7 +69,7 @@ export default class Select2 extends Component { | |||
} | |||
|
|||
render() { | |||
const { data, ...params } = this.props; | |||
const { data, value, ...params } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem with React warning was here, because select receive property value
, but we not need it
e368b8b
to
db8269a
Compare
I think feature is ready. What is your opinion? @rkit |
Sorry for the long answer… Now I am checking this feature. |
|
779b49d
to
3a424f7
Compare
@rkit fix code style and bug with code |
Thanks! Tomorrow will be release. |
👍 |
It seems there is a small discrepancy in logic: if |
multiple: true and defaultValue isn't compatible options. multiple as false, defaultValue not replaced on value => it's only default init by value. It may be replace with setValue in componentDidMount. Anyway, defaultValue it's very strange prop. |
|
3a424f7
to
daf64c8
Compare
@rkit You are right, my solution was overcomplicated. I fix it |
daf64c8
to
d7146f4
Compare
@lexich You still in process? I still not sure about this: if (!defaultValue && value !== (void 0)) {
this.setValue(value);
} if |
d7146f4
to
46ee812
Compare
@@ -45,6 +51,16 @@ export default class Select2 extends Component { | |||
this.props.events.forEach(event => { | |||
this.el.on(event[0], this.props[event[1]]); | |||
}); | |||
const { defaultValue, value } = this.props; | |||
if (defaultValue === (void 0) && value !== (void 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkit Fix: setValue if only defaultValue isn't defined
Thanks! |
@lexich I found a few problems with
|
i wrote custom implementation for our case #19 |
This is a good solution, thanks. |
export default class Tags extends Component {
constructor(props) {
super(props);
this.state = { value1: ['feature'] };
}
render() {
const { value } = this.state;
return (
<Select2
data={['bug', 'feature', 'documents', 'discussion']}
value={ value1 }
onChange={(e)=> {
this.setState({ value1: $(e.target).val() });
}}
/>
);
}
} We have value1 === "feature". componentDidMount hook invoke setValue. setValue triggered onChange hook. Our implementation (I think it's the most common implementation) call setState of value1. Also shallowEqual need for #18 |
It's necessary when we value was changed from external.