1
Hello, I created a "part" field of the rest of my form, and I would like it to have the same "face" as the rest, I did a validation for it, to check whether or not there is already an element in the database, it shows the same message as the others, only that I would like the field not to pass this validation beyond the message the input around to turn red. How could I do that?
Code jQuery
var ordertxt = $j("#ordertxt");
ordertxt.blur(function() {
$j.ajax({
url: '<?php echo Mage::getUrl('contato/index/verifica') ?>',
type: 'POST',
data:{"ordertxt" : ordertxt.val()},
success: function(data) {
console.log(data);
data = $j.parseJSON(data);
$j("#msg_pedido").text(data.ordertxt);
}
});
});
Input you would like to leave red
<input style="height:25px; width:262px; display: block;" name="order" id="ordertxt" class="input-text required-entry" type="text" />
Where the error appears
<p style="color: #ee001c; font-size: 0.9166em;" id="msg_pedido" name="msg_pedido"></p>
Sample image
Solution:
var ordertxt = $j("#ordertxt");
ordertxt.blur(function() {
$j.ajax({
url: '<?php echo Mage::getUrl('contato/index/verifica') ?>',
type: 'POST',
data:{"ordertxt" : ordertxt.val()},
success: function(data) {
console.log(data);
data = $j.parseJSON(data);
if (data['ordertxtx'] == true ) {
$j("#msg_pedido").hide(data.ordertxt);
$j("#ordertxt").css("border","1px solid #ddd");
} else {
$j("#msg_pedido").show(data.ordertxt);
$j("#msg_pedido").text(data.ordertxt);
$j("#ordertxt").css("border","1px solid red");
}
}
});
});
I did, and I put more things when I return to the other field, because the user will have to correct.
– Gustavo Souza