`editor.add()` and editor.dependent
`editor.add()` and editor.dependent
I have a field in edit it is an disable input, on create it needs to be a select2 below in the code i use to fill the select this works as i expect it to. I am using this method because I am searching through several thousand numbers and if the record is in the database already i will not be in the select. So I cannot have the select in the edit side.
editor.on("onInitCreate", function () {
editor.clear('PartLabelData.Part_Number');
editor.add({
label: "Part Number",
name: "PartLabelData.Part_Number",
type: "select2",
opts: {
width: '100%',
ajax: {
placeholder: {
id: '-1',
text: 'Select a Partnumber.'
},
url: "wsTraceSetup.asmx/GetPartForPackAddPartJson",
dataType: 'json',
delay: 250,
data: function(params) {
return {
searchIn: params.term // search term
};
},
processResults: function(data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function(markup) { return markup; }, // let our custom formatter work
minimumInputLength: 0
//templateResult: formatRepo, // omitted for brevity, see the source of this page
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
}
});
however when i add
editor.dependent("PartLabelData.Part_Number", function(val) {
editor.field("PartSettings.Part_Number").set(val);
editor.disable('PartSettings.Part_Number');
});
The event does not fire.
I have also tried a change event on the select as well (after doing some searching i found)
$('select', editor.field("PartLabelData.Part_Number").input()).on('change', function(e, d) {
editor.field("PartSettings.Part_Number").set(val);
editor.disable('PartSettings.Part_Number');
});
all these events are in
$(document).ready()
I cannot link the page
This question has an accepted answers - jump to answer
Answers
At what point does the event not fire - when disabled in edit mode? Does it then work if you are creating a new row?
Thanks,
Allan
On Edit I have just a regular input that is disabled as "PartLabelData.Part_Number" is the primary key in the table. The event does not fire on creating a new record. "PartSettings.Part_Number" is the primary key in a joined table. I would like to set the value and disable the field when "PartLabelData.Part_Number" is selected in the select2 control.
Are you able to give me a link to a page showing the issue please? I haven't been able to reproduce that locally - the Editor
change
event occurs when the field is disabled and a value is set via the API or internally.Allan
Well after a little trial and error I think I have got it. Instead of
I did
adding the .dependent at the end of the .add. I am not sure if this is the correct solution to my question but it does work.
Paul