Creating a custom field type plug-in for multiselect
Creating a custom field type plug-in for multiselect
I'm struggling to come to terms with whats needed for a multiselect as a field type.
At the moment I have a field type select with the ipopts set to:
[code]"ipOpts":publicaions_loader() //function is called and select field is filled from get_publications.php[/code]
[code]//GET PUBLICATIONS
var publicaions = new Array({"label" : "a", "value" : "a"});
function publicaions_loader(){
publicaions.splice(0,1);
$.ajax({
url: 'db/get_publications.php',
async: false,
dataType: 'json',
success: function (json) {
for(var a=0;a
At the moment I have a field type select with the ipopts set to:
[code]"ipOpts":publicaions_loader() //function is called and select field is filled from get_publications.php[/code]
[code]//GET PUBLICATIONS
var publicaions = new Array({"label" : "a", "value" : "a"});
function publicaions_loader(){
publicaions.splice(0,1);
$.ajax({
url: 'db/get_publications.php',
async: false,
dataType: 'json',
success: function (json) {
for(var a=0;a
This discussion has been closed.
Replies
Allan
[code]"events": {
"onPreSubmit": function (json, data) {
if($.isArray(data.pubs_sent_to)) data.pubs_sent_to = data.pubs_sent_to.join(', ');
}
}
[/code]
But I get this error
TypeError: data is undefined
...if($.isArray(data.pubs_sent_to)) data.pubs_sent_to = data.pubs_sent_to.join(', '
Allan
ReferenceError: data is not defined
How would I insert it back into the JSON?
Would doing the following replace the value of data.data.pubs_sent_to in the JSON? [code]data.data.pubs_sent_to = data.data.pubs_sent_to.join(', '); [/code]
CHANGED IT TO THIS (now no type or reference error):
[code] editor.on( 'onPreSubmit', function (json, data) {
console.log(data.pubs_sent_to);
if($.isArray(data.pubs_sent_to)) data.pubs_sent_to = data.pubs_sent_to.join(', ');
console.log(data.pubs_sent_to);
});
[/code]
[code]console.log(data.pubs_sent_to);[/code] returns undefined
AND STILL GETTING THIS (Do I need to push it back to the JSON, if so how?):
[code]
Notice: Array to string conversion in /sysadmin/db/press_release/lib/Database/Driver/Mysql/Query.php on line 78
{"id":"row_14","error":"","fieldErrors":[],"data":[],"row":{"DT_RowId":"row_14","id":"14","acyear":"2014\/2015","pubs_sent_to":"Array","name":"ghj","contact":"ghj","published":"fff","date":"ghj"}}[/code]
[code]
"onPreSubmit": function (o) {
if(o.action=="create"||o.action=="edit"){
o.data.pubs_sent_to = o.data.pubs_sent_to.join(',');
o.data.published = o.data.published.join(',');
}
}
[/code]
& for the form....
[code]
$('select', editor.node( 'pubs_sent_to' )).attr('multiple','multiple');
$('select', editor.node( 'published' )).attr('multiple','multiple');
[/code]
Excellent to hear that you've got it working - thanks for posting your solution!
Allan