开发者

Do something when input field gets updated through jquery

开发者 https://www.devze.com 2023-03-23 07:25 出处:网络
I have input field <input type=\"text\" name=\"vehicle_make[]\" id=\"make1\"/> and i have help dropdown that updates this field if user choose to do so. I do it trough standard jquery code

I have input field

<input type="text" name="vehicle_make[]" id="make1"/>

and i have help dropdown that updates this field if user choose to do so. I do it trough standard jquery code

$("#make1").val("value");

Problem is, since i use validate plugin to validate this field, if user click on validate before entering anything in that box, he will get notice that he needs to fill it, but then if he fills it trough dropdown, validate plugin will not detect it until user click on submit again.

I know i could call submit in function in which i process dropdown, but i think that it is not right solution, since i would need to check if validation is already done before doing that (since if it is not, it would start vali开发者_如何学Pythondation before i want it to start).

I also need to tie some other things to that field also, so i would like to know is there is a way in which i could write function so it always check if field is filled, even if user did not fill it directly.

Sorry if i didn't explain everything right, this is my first message here.


Try this

$("#make1").change(function(){

   //do something there 
});


I have found solution. First, i created js variable form_submitted, and added onclick event to submit button, to change value of variable form_submitted to yes. Then, i created function:

function update_validation(){
    if(form_submitted == 'yes'){
        $("#my_form").valid();
        };
    };

that i call when user do something that is not detected regularly with validate plugin. This function manually starts validation again, but only if it has been started before by clicking on submit.

0

精彩评论

暂无评论...
验证码 换一张
取 消