-
Notifications
You must be signed in to change notification settings - Fork 38
Preferred method of validating a checkbox? #31
Comments
Try binding to the <input
id="agreeCheckbox"
type="checkbox"
name="agree"
className="formControl"
ref="agree"
valueLink={this.linkState('agree')}
onChange={this.handleValidation('agree')}/> |
Putting that validation on the onChange doesn't allow me to actually click the checkbox i.e. when I click on it, it stays unchecked. |
Yeah that makes since because you are using the <input
id="agreeCheckbox"
type="checkbox"
name="agree"
className="formControl"
ref="agree"
value='on'
checked={this.state.agree === 'on'}
onChange={this.onCheckboxChange('agree')}/>
...
onCheckboxChange: function(fieldName) {
return function (event) {
var value = event.target.value;
var state = {};
state[fieldName] = value;
this.setState(state, this.handleValidation(fieldName));
}.bind(this);
} |
That last suggestion works for me. Almost. When I click the checkbox, I see the following error in the console: The error appear to be in the Also, can this same approach be used for radio inputs as well? |
I'll put together some examples for these scenario's over the weekend. stay tuned. |
Thanks...appreciated! |
How would I go about validating whether a checkbox is on? The validation seems to be triggered when I click on the checkbox (turning it on) and when I turn it off validation goes away. When it is clicked on again nothing is triggered.
My JOI validatorTypes looks like this
and my input looks like this
Thanks in advance
The text was updated successfully, but these errors were encountered: