elclanrs / jq-idealforms-old

The ultimate framework for building and validating responsive HTML5 forms.
665 stars 95 forks source link

Ajax giving unknown error when value is set #135

Open estilian opened 11 years ago

estilian commented 11 years ago

Well here is the case. I have a block element containing my form. This block is showing when user is trying to add or edit elements. For the inputs that should have unique value (username for example) I have ajax checking through a php with mysql request from the users database. Up to here everything is perfect.

The problem is when I load the form for editing existing user. At the beginning of the form I'm making a query to the db with the user's id to select all his data and I'm inserting it as values for all the inputs. But when a certain input has ajax filter and a value that I set it always appears as invalid (colored in red) but there is no message next it. The only way to validate it is to focus on it and change something in it (for example - insert a space and delete it) to make the ajax run and return that it's valid. As mush as I see the default statement of the ajax filter is invalid and since it doesn't make a request until I trigger the keydown event it's say that the input is invalid. Another problem was that the ajax was thinking that the current value when editing is not allowed as it exists in the database, but I have solution for that - I'm just sending the id of the current edited user as a get parameter in the ajax and I'm excluding it from the mysql request.

Here is part of the code: < label for="'.$k.'">'.$v['name']< /label> < input type="text" name="'.$k.'" value="'.(isset($object[$k])?$object[$k]:'').'" /> $validate_js[] = '".$k."': {\n filters: '".($r?'required':'').($u?' ajax':'')."',\n data: { '.($u?", ajax: {url:'check_exist.php".(isset($object[$k])?'?id='.$id:'')."'}":"")." }\n }

This is something I create dynamically with an array. I have deleted a lot from the original code to make it more clear. $k is the key (the name from the database) For example: username $v['name'] is the title of the input. For example: Your username: $object is set only when editing and it contains all the user's data in an array where keys are the input names from the database. $validate_js is an array that I print inside the javascript to create different dynamic filters for each input I create. $r is a boolean if the current input is required or not. $u is a boolean if the current input should be unique meaning that it should not have a dublicate in the database.

Once again - the problem is that when I add value="" to the input and it has the ajax it's always red at the beginning. I tried to refresh the entire form with all possible events: $myform.reset().fresh().focusFirst(); - no luck... the inputs are still invalid.