jquery - How To: a required input on edit form, unchanged from default value, should be valid -


here's example of 1 of several inputs on create form (note value empty). in context validation (query.validate.unobtrusive) works expected requiring user fill in required fields in order submit form.

        <div class="form-group">             <div class="col-sm-offset-1 col-sm-8">                 <input class="form-control" id="legalname" name="legalname" type="text"                      value="" placeholder="business legal name"                      data-val-required="legal name required." data-val="true" />                 <span class="field-validation-valid" data-valmsg-for="legalname"                      data-valmsg-replace="true"></span>             </div>         </div> 

for edit form use same html pre-fill each input current value (in case value="@model.legalname")

the problem is, though each field pre-filled value, built-in validation prevents submitting form, complaining required fields haven't been filled in.

the behavior want is:

  1. any input on page may left untouched current value
  2. any input user changes must "pass" validation (e.g. nonempty, proper e-mail address)

for create case, form validation feels "automatic" in right thing. there "automatic" way edit case? or have manually (by coding rules)?

many thanks, eric

never mind... i'm idiot today. form validation bit working fine. it's model binder that's got issue... sigh.

that said, hasn't been complete waste of time read there useful nugget here.

the model used on form contains, purely convenience, class has couple of own [required] properties. properties aren't represented on edit form coming empty.

thus, moral of story is: careful using [required] , careful put in view models.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -