modify editor fields

modify editor fields

kokotkokot Posts: 7Questions: 0Answers: 0
edited May 2012 in General
Hi there,
is it possible to somehow change fields depending on what fields I selected before ?
I mean like, you have 2 fields in editor, both are select dropdowns. I know there is ipOpts parameter that allows me to fetch select values from DB, but what if i want to select this fields depending on what i've selected before in field like "town".
[code]var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "php/table.test.php",
"domTable": "#zoznam",
"fields": [
{
"label": "town",
"name": "town",
"type": "select",
"ipOpts":loader1()
},
{
"label": "street",
"name": "street",
"type": "select",
"ipOpts":loader2()
}
],
} );
[/code]
loader1() will load towns from database and loader2() will load streets from database. I need from loader2 to load only streets what are in town field that was selected before. It will be probably something like :
[code]
{
"label": "street",
"name": "street",
"type": "select",
"ipOpts":loader2(town.selected.value)
}
[/code]
town.selected.value is what i need to give there as parameter. And of course, i need to refresh street field dynamically depending what's actually selected in town field..

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Currently I'm afraid you would need to remove the field (API: clear) and then add (API: add) the field with the new options.

    I'll most certainly be looking at making this more flexible for v1.1 and I'll be looking to see what would be involved in allowing options to be dynamically reconfigured in v1.0.1.

    Thanks for the feedback on Editor!

    Allan
  • kokotkokot Posts: 7Questions: 0Answers: 0
    API: clear and then add (API: add) are good way to do it, but i need to check if user changed the visible field and then make another field visible with add/show method. But how to check if user changed value in some editor field?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > But how to check if user changed value in some editor field?

    You'd need to bind an event to the element. Something like:

    [code]
    $(document).on( 'change', '#DTE_Field_first_name', function () {
    // value was changed...
    } );
    [/code]

    I think ultimately Editor should provide events that you can listen for when initialising the fields - added to the roadmap. Hope to target 1.1 with that.

    Regards,
    Allan
This discussion has been closed.