I have an input field, which is using jQuery's autocomplete method. The user starts typing the user's name, and receives a list of results. Once that result is selected, more input fields are shown, in which this user has more details (for this the data is brought with AJX in the background).
Also the selected user name is copied in the autocomplete field. I am doing this hidden input, because I want to prevent the user from changing the username without selecting a username from the list of suggestions. I am I am using jQuery to do this using So when the user now changes the value of the visible user input field (with just typing), notice is displayed, stating that it has to select a name from the list, it actually works fine. . But, I have a strange behavior, the user opens the form to edit the user. She starts typing a username, and selects one (more input fields are shown + hidden input is set). But for some reason, I get this notice that I have to choose a username. As soon as I click on the next field, this error disappears. Obviously, after the selection of jQuery username, the input is not being checked. Either way, can I force jQuery to modify the form again after the hidden input is set? This is my (short) jQuery code: Not sure Meets the requirement but you can easily use I think the problem is because the property of jquery verification "onfocusout" is by default Is right from If the onfocast event is triggered before choosing a username, then you might try overriding "onfocusout" such as equalTo validation. This compares with the value of visible usernem input field hidden.
$ (document) .ready (function () {// autocomplete $ ("# username"). Autocomplete ( {Source: function (request, response) {$ .ajax ({url: "http: //localhost/users.php", content type: "app / jason; charset = utf-8", data type: "jsnp" , Data: {search: request .term, uid: "ehtias" // this value is created server side -> it only shortens the list by selecting users related to this administrator), success: function ( Data) {response ( $ .map (item: "item.uid +"), "value: item.username, username: item.username, groupnumber: item.groupnumber}}) $ (" # groupnumber "));}}}}; }, MinNamban: 0, // Write input value: Choose function (Event, UI) {$ ("# Czech User Name"). Val (ui.item.username); $ ("# groupnumber"). Val (ui .item.groupnumber); Show all (); // it just shows all other input fields, is not relevant}}) Validate $ ("# user credit") Validate ({Rules: {Username: { Equivalent: "# check username"}, group number: {REQUIRED: true, Meanline: 2, Number: true}}, Message: {cnAntragsteller: {equalTo: "Select a user from the dropdown!"}, Group number: {Required: "You need to specify a group number!", Minnamban : "The specified group number is too small!", Number: "You have to specify a numerical value!"}}, Error placement: function ($ error, $ element) {var name = $ element.attr ("name") ; $ ("#" + Name + "Error") Attachment ($ error);}})})
$ ("# useredit"). Valid () Revise the form you want in it again. Apart from this, you can also see if there is a proper asset for onkeyup, onfocusout etc. ...
$ (form). Validate ({onfocusout: function} {var dovalid; // Some things are true or false to determine the Dolied; if (dualid) {return $ (element). Valid ();} else {return true}}} });
Comments
Post a Comment