Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Dynamic FormItem Titles

    We have a database table containing field names and what their corresponding field title should be in a DynamicForm. I noticed that there is not a setTitle() on FormItems so I am attempting to override getTitle() to achieve my goals. I am successfully able to override getTitle() to dynamically assign the title as the form is built, however I am having trouble incorporating the logic to assign the title from the database.

    I am setting up the form as follows:
    Click image for larger version

Name:	Form.PNG
Views:	85
Size:	79.2 KB
ID:	268269

    The getCustomFieldLabel() function fetches the record based on the field name passed in:
    Click image for larger version

Name:	getCustomFieldNames.PNG
Views:	58
Size:	8.4 KB
ID:	268270

    The fieldLabel is assigned correctly in the fetchData() callback function, but I am having a hard time figuring out how I can return that value from the getCustomFieldLabel() function. Since fetchData() is run asynchronously, I am unable to simple return fieldLabel after it executes as the image shows. Is there a way I can access the data returned from fetchData() outside of the callback function? Is there a better way I can accomplish dynamic titles for FormItems?

    Thanks!

    Version: v12.1p_2021-06-05/Pro

    #2
    No need to do any of this. Just move the "fields" out of the statementFormDefaults block and build the fields inside a function after you've already loaded title information from the server, then only create the statementForm AutoChild at that point.

    Two further notes:

    1. you may want to consider a DynamicDSGenerator instead of this approach - see QuickStart Guide

    2. in general, if a method doesn't not have information about how overriding it would work, don't do so. You will be relying on undocumented behaviors, and your code could break in the future.

    Comment

    Working...
    X