jquery tokeninput field is cleared when there are other validation error(s) when submitting

97 views Asked by At

I'm using jquery tokeninput to select multiple items coming from the database, using autocompletion as they try to find each item. However, if there are validation errors in other fields when submitting the form, the tokeninput field is cleared and the user's got to select the items again. My worry now is to persist the selected item even if there are validation errors in other fields.

Here's my script

 $("#States").tokenInput("/User/getPreferredStates",
 {
    placeholder: 'Primary Skills',
    preventDuplicates: true,
    theme: 'facebook',
    tokenValue: 'name',
 });

and my html:

 @using (Html.BeginForm("Profile", "SignUp", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
 {
    @Html.AntiForgeryToken()
    [...]
    <div class="form-group">
        @Html.TextBoxFor(model => model.States, htmlAttributes: new { @class = "form-control,text-box", id= "States" })
    </div>
   [...]
0

There are 0 answers