Problem with set() and val() functions
Problem with set() and val() functions
Hello,
I have a problem with functions set()
and val()
I have created new page at my server with extracted from Editor-PHP-1.5.4.zip files only.
The only 2 files that I have modified are:
1) php/config.php (hostname and credentials for database connection)
2) examples/simple/simple.html
In the second file in line 68th I have added one line:
editor.field('first_name').set("MAKING YOU HAPPY");
And when I call simple.html in my browser the "First name" field (which supposed to make me happy) is empty :(
editor.field('first_name').val("MAKING YOU HAPPY"); // don't work either
editor.set('first_name',"MAKING YOU HAPPY"); //don't work
editor.val('first_name',"MAKING YOU HAPPY"); //don't work
editor.field('first_name').def("MAKING YOU HAPPY"); // the only one that works...
Is this a bug or am I doing something wrong?
Since obviously problem is with js then it should not be related with my www server configuration (js is running in browser). I am using new chrome and firefox.
Full js code of simple.html (additional code in line 32nd):
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../php/staff.php",
table: "#example",
fields: [ {
label: "First name:",
name: "first_name"
}, {
label: "Last name:",
name: "last_name"
}, {
label: "Position:",
name: "position"
}, {
label: "Office:",
name: "office"
}, {
label: "Extension:",
name: "extn"
}, {
label: "Start date:",
name: "start_date",
type: "datetime"
}, {
label: "Salary:",
name: "salary"
}
]
} );
editor.field('first_name').set("MAKING YOU HAPPY");
$('#example').DataTable( {
dom: "Bfrtip",
ajax: "../php/staff.php",
columns: [
{ data: null, render: function ( data, type, row ) {
// Combine the first and last names into a single table field
return data.first_name+' '+data.last_name;
} },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
} );
This question has an accepted answers - jump to answer
Answers
Setting the value of a field is only useful once the form is open (in create, edit or remove mode). Otherwise, when you open the form, the values are all set to whatever value needed to be edited (or the default).
Perhaps you want to try setting the default -
field().def()
.Allan
For those who look for complete answer, it is in my other topic:
https://datatables.net/forums/discussion/32749/create-button-with-extra-function