className no longer working in the new Editor release
className no longer working in the new Editor release
Hi Allan,
I had implemented masking of phone numbers using Editor 1.5.6 using className and it worked fine. I noticed today that with Editor 1.6 it is no longer working. I tried it with id and it worked again. Here is the code including the code for the masking which now is doubled unfortunately because I still need to keep the className for scope that is outside of DataTables.
I get no error message by the way. I simply don't see the masking any longer and cannot enter anything into the phone number fields.
Kind regards
Roland
var userPhoneEditor = new $.fn.dataTable.Editor( {
ajax: {
url: 'actions.php?action=tblUserPhone',
data: function ( d ) {
var selected = userTable.row( {selected: true} );
if (selected.any()) {
d.user = selected.data().user.id;
}
}
},
table: "#tblUserPhone",
fields: [ {
label: "Phone Type:",
name: "phone.type",
type: "select",
options: [
{ label: "Work", value: "work" },
{ label: "Mobile", value: "mobile" },
{ label: "Alternate", value: "alternate" }
]
}, {
label: "Country Code:",
name: "phone.countrycode",
//className: "phoneCountryCode" // id: ... can also be set
id: "tblPhoneCountryCode"
}, {
label: "Area Code:",
name: "phone.areacode",
//className: "phoneAreaCode"
id: "tblPhoneAreaCode"
}, {
label: "Number:",
name: "phone.phone",
//className: "phonePhoneNumber"
id: "tblPhonePhoneNumber"
}
]
} );
userPhoneEditor
.on('open', function() {
maskPhone();
});
//duplication with id's due to dt bug
function maskPhone() {
$.myMask.definitions['b'] = "[0-9 ]";
$.myMask.definitions['c'] = "[0-9-xX ]";
$.myMask.definitions['8'] = "[1-9]";
$(".phoneCountryCode").myMask("+8?bb",{placeholder:"_"});
$(".phoneAreaCode").myMask("9?bbbb",{placeholder:"_"});
$(".phonePhoneNumber").myMask("89c?cccccccccccc",{placeholder:"_"});
$("#tblPhoneCountryCode").myMask("+8?bb",{placeholder:"_"});
$("#tblPhoneAreaCode").myMask("9?bbbb",{placeholder:"_"});
$("#tblPhonePhoneNumber").myMask("89c?cccccccccccc",{placeholder:"_"});
//$("#date").myMask("9b.9b.99bb",{placeholder:"DD.MM.YYYY"});
}
This question has accepted answers - jump to:
Answers
If you comment that
fields.className
option back in, and then right click on the field in the editor form and find the containingdiv
for the field in the browser's inspector. Is the class there?Thanks,
Allan
Hi this is what it looks like with className commented back in and id commented out. No class.
This is the posted version. The right id shows up.
It should appear on the
div
element a few up from theinput
. Attached is a screenshot showingmyTestClass
being applied to the field.Allan
Sorry, but it isn't there either
And a little more:
It's in the first line of the second block of code there:
I think the issue is that the selector here:
is not correct. It should perhaps be:
The
fields.className
option should never have been applied to theinput
element directly. It could have been with theattr
option.Allan
Why should the className option never have been applied to the input element directly? You are doing it with the id option yourself! (see above)
Now it is inconsistent: In case I use "className" I need to code this:
If I use "id" I need to code this:
Because the id option attaches the id to the input element directly whereas className attaches the class to the containing div. In addition my preferred solution (attaching the class to the input element) worked in the previous Editor release.
Even though it is inconsistent I can live with this solution. I had to change my own HTML and moved my classes from the input field to the containing divs. And now this code works for your and my HTML:
Unfortunately this code requires that the class names may not be applied to the input element directly any longer. If you do this the selector does not find the class.
That wasn't a feature that I had planned to put into Editor. If that was happening with the 1.5 releases, it was a mistake!
You can use the
attr
option for that:For the
text
field type theattr
option will apply the attributes to theinput
tag.Allan
This indeed is a much better solution. Got rid of "className" and "id" and will use the "attr" option now. Many thanks. Didn't find it in the reference though. "fields.attr" has no match whereas "fields.name", "fields.type" etc. can be found.
It is detailed in the
text
reference documentation.Allan
Great you answered another question I had in mind: How do I set a placeholder
Thanks again, Allan!