populate a non-database field in editor using dependent on a select

populate a non-database field in editor using dependent on a select

d00mboyd00mboy Posts: 8Questions: 4Answers: 0

I don't have a test case or error messages, this is a general question. I'm using the PHP libraries and Oracle backend, current versions of datatables and editor.

Scenario is a very simple form where the user selects an identifier ("catalog-number") from a left-joined table. There is a second column in the left-joined table ("description") that I would like to use to populate a "placeholder" editor field when the form is in 'Create' mode, once the user selects the 'catalog-number'. The user then codes some additional fields that are saved to the database.

When the form is opened in 'Edit' mode, that value "description" is already populated via the join, but when the form is in 'Create' mode, it doesn't have the key for the left-join table reference yet, until the user sets the 'catalog-number'.

I am wondering if there is some way to use dependent to set a non-database field in the editor form to the "description" data when it is opened in 'Create' mode, based on the 'catalog-number' selected value. I don't want to edit this field or save it back to the database, I only want to display it to the user (in the editor form) while they are entering new records.

Answers

  • rf1234rf1234 Posts: 2,358Questions: 76Answers: 339

    No problem, regardless of whether you "create" a record or "edit" it, you just take the value of the "catalog-number" field and populate the "description" field with it. in this case it doesn't matter whether the "catalog-number" field was populated by the user's selection or by an ajax call.

  • rf1234rf1234 Posts: 2,358Questions: 76Answers: 339
    edited July 19
    editor
        .dependent('catalog-number', function (val, data, callback) {
            if (val > 0) { // or > "" or whatever
               this.set({'description': val})
               // set the value or the placeholder of the other field to something ... 
               // or whatever you need to do
            }   
            callback({});
        })
    
Sign In or Register to comment.