Skip to content

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

Open
@Abdulmoiz-Ahmer

Description

@Abdulmoiz-Ahmer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions