0
I’m having trouble generating mask reading(jQuery) on elements generated via innerHTML
. Only that the validator
works and after trying to insert a die outside the mask it loads the page with the mask.
Here to Mask:
<script>
$(document).ready( function() {
$.validator.addMethod("conceito", function (value, element) {
return ((/^((((([1]{1}[0]{1})\,([0]{1}))|((([0]{1})(\d){1}))\,(\d){1}))|([F]{1}))?$/i.test(value)));
}, "Digite uma média válida (valores entre 00,0 e 10,0 ou o conceito F)");
$('.conceito').mask("A9,9");
$('#gerar_conceitos').validate({
// Define as regras
errorElement: "em",
errorContainer: $(".error"),
errorPlacement: function(error, element) {
element.parent().append(error);
},
success: function(label) {
label.text("Sem erros.");
},
messages: {
conceito: {
required: "Digite uma média válida (valores entre 00,0 e 10,0)"
}
}
});
});
</script>
And the innerHTML:
<script type="text/javascript" language="javascript">
function msalterar(numerodematricula,conceito){
c=document.getElementById('conceito['+numerodematricula+']');
inner ="<label>Média:/label>";
inner += "<input type=\"text\" size \"4\" class=\"conceito\" name=\"conceito["+numerodematricula+"]\" value=\""+conceito+"\">";
c.innerHTML = inner;
dfinalizar();
}
</script>
I don’t know if I understand the question very well but one observation: the input you are creating dynamically needs to receive the mask again. The mask is initially only applied to elements that already came in the page load.
– Joao Paulo
Exact Joao Paulo.
– user5988
Exactly, so have you already done this and the error continues? If you can see in the Browser Console(F12) if you accuse some javascript error.
– Joao Paulo
Exactly it comes without the mask but when I try to send a data that does not have the mask it resets the page and reads the mask but I have to force sending something wrong to make it happen.
– user5988
Try to put $('.concept'). Mask("A9,9"); between the line> c.innerHTML = Inner; and the line dfinalize();
– Joao Paulo