`editor.add()` and editor.dependent

`editor.add()` and editor.dependent

farmerphfarmerph Posts: 10Questions: 2Answers: 0

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

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    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

  • farmerphfarmerph Posts: 10Questions: 2Answers: 0
    edited November 2017

    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.

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    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

  • farmerphfarmerph Posts: 10Questions: 2Answers: 0

    Well after a little trial and error I think I have got it. Instead of

        editor.dependent("PartLabelData.Part_Number", function (val) {
            editor.field("PartSettings.Part_Number").set(val);
            editor.disable('PartSettings.Part_Number');
        });
    

    I did

        editor.on('onInitCreate', function(){
             editor.clear('PartLabelData.Part_Number');
             editor.add({
                 label: "Part Number",
                 name: "PartLabelData.Part_Number",
                 type: "select2",
                 opts: {
                       //ajax call here
                   }
              }).dependent("PartLabelData.Part_Number", function (val) {
                   editor.field("PartSettings.Part_Number").set(val);
                   editor.disable('PartSettings.Part_Number');
              });
        })
    

    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

This discussion has been closed.