editor.clear()->Cannot read property 'destroy' of undefined

editor.clear()->Cannot read property 'destroy' of undefined

fattestfattest Posts: 3Questions: 1Answers: 0

Hi!
what am I doing wrong!
gives an error message?

editor.clear(["org_name","short_name","inn","kpp","business_address","post_address","bank_account","bik_bank",
        "function","surname","name","patronymic","phone","email","ogrnip","serial_pass","number_pass","issued_date_pass"]);->Cannot read property 'destroy' of undefined
$('input', editor.node( 'org_type' ) ).on( 'change', function () {
        editor.clear(["org_name","short_name","inn","kpp","business_address","post_address","bank_account","bik_bank",
            "function","surname","name","patronymic","phone","email","ogrnip","serial_pass","number_pass","issued_date_pass"]);
        switch (editor.get( 'org_type' )) {
            case 1:
                editor.add([
                    {
                        "label": "Наименование организации",
                        "name": "org_name"
                    },
                    {
                        "label": "Краткое наименование",
                        "name": "short_name"
                    },
                    {
                        "label": "ИНН",
                        "name": "inn"
                    },
                    {
                        "label": "КПП",
                        "name": "kpp"
                    },
                    {
                        "label": "Юридический адрес",
                        "name": "business_address"
                    },
                    {
                        "label": "фактический адрес",
                        "name": "post_address"
                    },
                    {
                        "label": "расчетный счет",
                        "name": "bank_account"
                    },
                    {
                        "label": "БИК",
                        "name": "bik_bank"
                    },
                    {
                        "label": "Должность руководителя",
                        "name": "function"
                    },
                    {
                        "label": "Фамилия",
                        "name": "surname"
                    },
                    {
                        "label": "Имя",
                        "name": "name"
                    },
                    {
                        "label": "Отчество",
                        "name": "patronymic"
                    },
                    {
                        "label": "Телефон",
                        "name": "phone"
                    },
                    {
                        "label": "E-mail",
                        "name": "email"
                    }
                ]);
                break;
            case 2:
                editor.add([
                    {
                        "label": "Наименование ИП",
                        "name": "org_name"
                    },
                    {
                        "label": "Краткое наименование",
                        "name": "short_name"
                    },
                    {
                        "label": "ИНН",
                        "name": "inn"
                    },
                    {
                        "label": "ОГРНИП",
                        "name": "ogrnip"
                    },
 
                    {
                        "label": "Юридический адрес",
                        "name": "business_address"
                    },
                    {
                        "label": "фактический адрес",
                        "name": "post_address"
                    },
                    {
                        "label": "расчетный счет",
                        "name": "bank_account"
                    },
                    {
                        "label": "БИК",
                        "name": "bik_bank"
                    },
                    {
                        "label": "Должность руководителя",
                        "name": "function"
                    },
                    {
                        "label": "Фамилия",
                        "name": "surname"
                    },
                    {
                        "label": "Имя",
                        "name": "name"
                    },
                    {
                        "label": "Отчество",
                        "name": "patronymic"
                    },
                    {
                        "label": "Телефон",
                        "name": "phone"
                    },
                    {
                        "label": "E-mail",
                        "name": "email"
                    }
                ]);
                break;
            case 3:
                editor.add([
                    {
                        "label": "Краааткое наименование",
                        "name": "short_name"
                    },
                    {
                        "label": "Фамилия",
                        "name": "surname"
                    },
                    {
                        "label": "Имя",
                        "name": "name"
                    },
                    {
                        "label": "Отчество",
                        "name": "patronymic"
                    },
                    {
                        "label": "серия",
                        "name": "serial_pass"
                    },
                    {
                        "label": "Номер",
                        "name": "number_pass"
                    },
                    {
                        "label": "Кем выдан",
                        "name": "issued_pass"
                    },
                    {
                        "label": "Дата выдачи",
                        "name": "issued_date_pass"
                    },
 
                    {
                        "label": "Отчество",
                        "name": "patronymic"
                    },
                    {
                        "label": "Адрес регистрации",
                        "name": "business_address"
                    },
                    {
                        "label": "Почтовый адрес",
                        "name": "post_address"
                    },
                    {
                        "label": "ИНН",
                        "name": "inn"
                    },
                    {
                        "label": "Телефон",
                        "name": "phone"
                    },
                    {
                        "label": "E-mail",
                        "name": "email"
                    }
                ]);
                break;
            default:
                alert('Я таких значений не знаю')
        }
    } );
} );

Answers

  • allanallan Posts: 63,791Questions: 1Answers: 10,511 Site admin

    gives an error message?

    What error message?

  • fattestfattest Posts: 3Questions: 1Answers: 0

    ...."issued_date_pass"]);->Cannot read property 'destroy' of undefined

  • allanallan Posts: 63,791Questions: 1Answers: 10,511 Site admin

    Oh sorry - it was hidden in the scrolling part!

    The error you are seeing will occur if you attempt to access a field which isn't defined (in this case destroying a field that doesn't exist).

    If you simply want to remove all fields, then I would suggest using order() to get the current fields - editor.clear( editor.order() ) would remove all existing fields for example.

    Allan

  • fattestfattest Posts: 3Questions: 1Answers: 0

    Thanks, I understand.
    I did so:

    var cleared = editor.displayed();
    cleared.shift();
    editor.clear(cleared);
    

    But there is another problem.
    After the addition of new fields do not load data

    p. s. sorry for my English

  • allanallan Posts: 63,791Questions: 1Answers: 10,511 Site admin

    After the addition of new fields do not load data

    They won't actually get the data from the table. You would need to use val() to set values for newly created fields.

    Perhaps it would be easier to simply include all of the fields in the form, and then use show() and hide() to show and hide the fields as you require, rather than adding and removing them.

    Allan

This discussion has been closed.