Skip to content
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

Unable to validate dynamically added array of fields with it? #18

Open
Abdulmoiz-Ahmer opened this issue May 12, 2020 · 0 comments
Open

Comments

@Abdulmoiz-Ahmer
Copy link

I have created a couple of fields all same.
`
//This is the code inside of my render return
this.state.fields.features.map((feature, index) => {
if (index != 0) {
return (

-

<Input type="text" onChange={(e) => this.handleChangeOfFeature(e, index)} className="float-left ml-1" name="features[]" value={feature} placeholder="feature" onBlur={this.form.handleBlurEvent}
onChange={this.form.handleChangeEvent} />

<Button type="button" color="primary" onClick={() => { this.addFeature("") }}>+


{console.log(this.state.errors.features)}
{/* {this.state.errors.features[index] ? this.state.errors.features[index] : ""} /}

)
} else {
return (
<Input type="text" onChange={(e) => this.handleChangeOfFeature(e, index)} className="float-left ml-1" name="features[]" value={feature} placeholder="feature" onBlur={this.form.handleBlurEvent}
onChange={this.form.handleChangeEvent} />

<Button type="button" color="primary" onClick={() => { this.addFeature("") }}>+


{console.log(this.state.errors.features)}
{/
{this.state.errors.features[index] ? this.state.errors.features[index] : ""} */}

)
}
})

//This is add same field
addFeature(value) {
let fields = this.state.fields;
fields["features"] = [...this.state.fields.features, value];
this.setState({
fields
});
}

This is what's inside my constructor method
this.state = {
fields: {
avatar: "",
features: []
},
errors: {
},
}
this.form = new ReactFormInputValidation(this);
this.form.useRules({
features: "required|array",
});
this.form.onformsubmit = (fields) => {

}
`
The problem is it's ok with empty strings. Laravel had rule to even validate inside of the array like.
array.*:"required"
How can i make it not ok with empty strings inside of array.

@Abdulmoiz-Ahmer Abdulmoiz-Ahmer changed the title Unable to validate dynamically array of fields with it? Unable to validate dynamically added array of fields with it? May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant