Fieldtype - variable select

Fieldtype - variable select

pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

Hi there,

Let me sketch the situation first:
I have a building. In each building live multiple residents. Each resident can have one or more budgets. (They can also have no budgets)
I made an editable overview per building in which I summarise which resident spend which amount.

My problem:
I would like to link a budget to each expense (fieldtype: select), but stumble over the difficulty that each resident has a different list of budgets. I managed to update the budget list when I'm working with a pop-up (ajax), but inline-editing is a different story.
I'm currently working with the preOpen event but triggering the ajax that retrieves the budget list even when the budget list hasn't been clicked slows everything down. Is there a way to only trigger the ajax when the budget field has been clicked?

Thanks in advance,
Gloria

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Use dependent(). That will let you make an Ajax request whenever the host field has its value changed.

    There is some more discussion about it here.

    Allan

  • pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

    Hey Allan,

    That does indeed make the updating a lot easier, but that only answers a part of my question.

    I would like to run certain validations during the preopen event but only when a certain column has been clicked (and only inline). Is there a way to check which column has been clicked within the preopen event?

    Kind regards,
    Gloria

  • pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

    Update
    I have tried using: editor.field().name()
    This gives me the error "uncaught exception: Unknown field name - undefined".

    When I change it to: editor.field('field_name').name()
    The error is gone, but obviously, the only result I get is 'field_name', unrelated to the field I've clicked.

    If I change it to:
    editor.on( 'preOpen ', function ( e, mode, action ) {
    console.log(editor.field(e).name());
    }
    The error changes to: uncaught exception: Unknown field name - [object Object]

    If I change it too:
    editor.inline(this, {
    submitOnBlur: true,
    submit : 'allIfChanged'
    });
    editor.on( 'preOpen ', function ( e, mode, action ) {
    console.log(editor.field(this).name());
    }
    The error message remains: uncaught exception: Unknown field name - [object Object]

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    displayed() is the method to use to get the field name of the field(s) displayed.

    Can your data be invalid if it is already in the table?

    Allan

  • pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

    Hey Allan,

    The displayed() code also doesn't work inside the preopen event.

    So I did:

    $('#myTable').on( 'click', 'td', function () {
        editor.inline( this );
        console.log(editor.displayed()[0]);
    } );
    

    It looks like this is what I need, except for the small detail that I only get the correct value when the editor hadn't been activated already.

    If I jump from residents to price to budget, without deactivating the inline editor, I'll get the result:
    'residents' - undefined - undefined

    Could this be caused by my version of the editor? (1.7.2)

    I was trying to use the preopen event to say that if there aren't any budgets for a certain resident, then the inline editor doesn't need to activate.

    Thanks in advance :smile: !

  • pcsintjanbaptistpcsintjanbaptist Posts: 20Questions: 9Answers: 1

    Update
    I found this page: link
    And noticed this part of the code:

    //  var fieldName = e.currentTarget.s.includeFields[0];
    var fieldName = editor.displayed();
    fieldVal = eval(`this.field("`+fieldName+`").val()`);
    

    The strange thing is; e.currentTarget.s.includeFields[0] does give me the result I need. editor.displayed() does not.

    So I'm going to asume that I have an outdated version of the editor script and simply go along with the e.currentTarget.s.includeFields[0] (which works for me).

    Thanks for your help :smile:

This discussion has been closed.