I am new to AngularJS and I have a simple test form as shown below. Without AngularJS validation, value in the input field is retained if the validation at server fails and the form is returned to the user. If I add AngularJS validation but the form is submitted when its invalid, validation fails at the server end and the form is returned to the user, but the input field is empty. I can see AngularJS is setting ng-empty
for this field.
I was browsing through and I could not find similar situation addressed anywhere yet. I was thinking may be I should add those form values to cookie and then refill if there is a validation error. Is this the only approach or is there a much simpler way to do this?
<s:form name="form" action="/actionname" novalidate="novalidate" >
<div >
<label>Name</label>
<s:textfield type="text" name="user.name" size="25" ng-model="name" ng-required="true" cssClass="formfield" />
<span class="customErrorMessage" ng-show="form['user.name'].$touched && form['user.name'].$error.required">Please enter your name.</span>
</div>
<div>
<s:submit type="button" cssClass="submitButton">Take me in!</s:submit>
</div>
</s:form>