DataTable.Editor.safeId()
Create an easy to use DOM id from an input string.
Please note - this property requires the Editor extension for DataTables.
Description
Editor field types will typically use the field's name to assign a unique id to the field's input element (or whatever element happens to be used for the field) as this can be useful if you wish to use jQuery to select specific elements.
DOM ids can have any character in this as of HTML5 including .. While perfectly valid it can cause issues with using CSS selectors since the dot is a class name separator. Editor also uses the dot as an object separator just like Javascript and SQL.
For example consider #myField.name - this is an id selector of #myField with a class of name. The dot can be escaped in the selector but this can make selectors look messy and is confusing for developers new to escaping selectors. As a result Editor provides this method for plug-in developers to create easy to use ("safe") ids for their input elements.
The functionality of this method is simple to replace the dot with a dash (-).
Type
DataTable.Editor.safeId( id )
Replace any dots (.) in a string with a dash (-) in order to make the string easy to use with a DOM id selector.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | id | No | |
ID to make safe. | |||
Returns:
string:
The safe ID.
Example
Create an easy to use id:
console.log(DataTable.Editor.safeId('myField.name'));
/* Output:
myField-name
*/