0
Good morning, I’m putting a mask on a field that formats a phone number, but you can see that the field ID is #Field_11690, as it was created by a Wordpress plugin.
( function( $ ) {
// jQuery MeioMask.
$( '#field_11690' ).setMask( '(99) 9999-99999' ).ready( function( event ) {
var target, phone, element;
target = ( event.currentTarget ) ? event.currentTarget : event.srcElement;
if ( 'undefined' === typeof type ) {
return;
}
phone = target.value.replace( /\D/g, '' );
element = $( target );
element.unsetMask();
if ( 10 < phone.length ) {
element.setMask( '(99) 99999-9999' );
} else {
element.setMask( '(99) 9999-99999' );
}
});
And for this reason I do not know if in production would continue the same ID, there is some other way I can declare the ID number of this field, or catch some Higher element?
Good for what you can see from the field ID, I believe that the field ID can be dynamic, or it can also be fixed, the plugin can save the ID for that field and always keep the same. If that’s the case, all right, you’d better confirm it. If not, I believe that the ideal would be for you to take a higher element than the field, like the form, or even a div. And to find it via jQuery, I believe that it should maintain a hierarchy always, independent of the ID.
– Vinicius Gabriel
We can help you better if you could show us in production what the hierarchy of elements looks like. And also confirm that the field id is changed in some way, check that the plugin saves the data from the generated forms in the database (some do so).
– Vinicius Gabriel
Hello Vinicius, I did the test and in production it saves the name of the random ID, however I saw that in the div that contains the input I can use, how do I access the input with the class you have in div?
– BrunoAngeoletto
Could you post the hierarchy code? So I can better illustrate how to get to the input from this div that you have.
– Vinicius Gabriel
`<div class="editfield field_11690 field_phone-with-ddd required-field visibility-adminsonly alt field_type_textbox">
– BrunoAngeoletto
<input id="field_11690" name="field_11690" type="text" value="" " Aria-required="true" Aria-labelledby="field_11690-1" Aria-describedby="field_11690-3">`
– BrunoAngeoletto
Inside the Div This input, you can tell me, how to access it to put in the jquery function up there?
– BrunoAngeoletto
I’ll post the answer down there, can you confirm that the 'field_telefone-com-ddd' class will always be in that div? And inside that div is just that input or there’s more?
– Vinicius Gabriel
The Class, will always be yes in this Div, there is a <Legend id="field_11690-1" between the div and the input, Thanks for the help, so post I already test and mark as answer.
– BrunoAngeoletto