Check this fiddle:http://jsfiddle.net/8b32e/
All working fine there. It validate fields. Check if digits, check if blank. If invalid error label appears, if valid it is disappears.
$("input").each(function () {
$(this).rules("add", {
required: true,
digits: true,
messages: {
required: 'It is required',
digits: 'Only digits can be there'
}
});
});
If I add remote rule to rule list, error label is appearing, but if field getting valid, only classes message
and error
are disappearing, but label is still shown (but must be removed). Check this fiddle : http://jsfiddle.net/2LRv7/7/
Block with rules with remoute:
$("input").each(function () {
var fieldName = $(this).attr('name');
$(this).rules("add", {
required: true,
digits: true,
remote: {
url: "/inc/json.php?action=get_last_counter_value",
type: "post",
data: {
id: fieldName
}
},
messages: {
required: 'It is required',
digits: 'Only digits can be there',
remote: 'Fix this please.'
}
});
});
What is this?
ADD:
php script from remote url:
$DBH = connectToDatabase();
$user_id = $_SESSION['OplataUser_ID'];
$counter_id = $_POST['id'];
$newValue = $_POST["".$counter_id.""];
$params = array();
$params['user_id'] = $user_id;
$params['counter_id'] = $counter_id;
$STH = $DBH->prepare("
SELECT CounterValue as Value FROM CounterValues
WHERE
UserID = :user_id
AND
UserCounterID = :counter_id
ORDER BY
DateCreate
DESC
LIMIT 1
");
$STH->execute($params);
$lastValue = $STH->fetch(PDO::FETCH_OBJ)->Value;
if($lastValue > $newValue)
{ $result = "false"; }
else
{ $result = "true"; }
print $result;
$DBH = null;
So this script returns only true
or false
.
` there like I did? – Sharikov Vladislav Mar 21 '14 at 20:42
` & jQuery that you couldn't just do with regular CSS. – Sparky Mar 21 '14 at 20:43
` tag. I tried your fiddle on my localhost and it still didn't working (don't working properly. jQuery removing classes, but not element still). If `errorPlacement` is removed all working fine. – Sharikov Vladislav Mar 21 '14 at 20:46