简体   繁体   中英

trigger field validation on form submit

i have a text input component which has a validator input prop for field level validation which gets triggered by event like clicking the field. I am using the text-input component multiple times in a form. How do i trigger field level validation for all text-inputs on form submit.

    <form id="update-for-homeaddress" action="/mycontact" method="POST" onSubmit={this.handleSubmit}>
    <Label labelFor="Nickname" labelText="Nickname:" required/>
        <TextInput inputName="Nickname"
                   inputType="text"
                   value={this.props.myhomeaddress.AddressAlias}
                   onChange={()=>{}}
                   validator={ValidateFactory.getMandatoryCheck()}
                   ref="TextInputRef"
          />

I suggest moving this code into a tag below. Put an ID in the form tag

then using this

$('document').ready(function()
{

    //Jquery validation codes
    $("#my_form").validate({
     submitHandler: submitForm
       });

    function submitForm()
    {
        //Submit form from here
    }
}

You need the jquery validation plugin here, you can add different validations then on

https://jqueryvalidation.org

I hope this helps in any way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM