Pre-loading input fields based on previous input in Editor

Pre-loading input fields based on previous input in Editor

BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0
edited June 2020 in Editor

Hi All,

I have 6 date fields to enter in editor, I am looking at automating last three date fields with +7 days it is recurring every 7th day.

Enclosed the code for your reference.

            {
                            "label": "Day 1 Date:",
                            "labelInfo": "<i>Enter the Day 1 Date.</i>",
                            "name": "date1",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        },
                        {
                            "label": "Day 2 Date:",
                            "labelInfo": "<i>Enter the Day 2 Date.</i>",
                            "name": "date2",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        },
                        {
                            "label": "Day 3 Date:",
                            "labelInfo": "<i>Enter the Day 3 Date.</i>",
                            "name": "date3",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        },
                        {
                            "label": "Day 4 Date:",
                            "labelInfo": "<i>Enter the Day 4 Date.</i>",
                            "name": "date4",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        },
                        {
                            "label": "Day 5 Date:",
                            "labelInfo": "<i>Enter the Day 5 Date.</i>",
                            "name": "date5",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        },
                        {
                            "label": "Day 6 Date:",
                            "labelInfo": "<i>Enter the Day 6 Date.</i>",
                            "name": "date6",
                            "type": "datetime",
                            "format": "ddd, D MMM YYYY"
                        }

In this last three date fields (date4, date5, date6) has to be automated like this date4 = date1+7days similarly for date5 and date6.

Thanks
Bala.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Would you expect those three date fields to be editable? Or would they be read-only and only be displayed in the table, rather than the form?

    Colin

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Hi Colin, thanks for looking into this.

    1) Yes, I want the date to be displayed in Editors form it has to editable and No read-only.
    2) The only automation I am looking at is - When I enter date1 as 9-06-2020 - date4 should automate with value of 9+7 days = 16-06-2020.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    This example will get you going. I've hijacked the salary field, so that when a record is edited, it gets set to start_date plus a week. For you, just do that to your date fields.

    Hope that helps,

    Colin

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Thank Colin, It helped me to understand the logic, but I am looking at change that should happen from Editor form before data getting inserted into the db. Currently I could see the changes(+7days) only after inserting into the table - Can't we make it display before inserting.

    Once again thanks for making the example it was very handy.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Can't we make it display before inserting.

    Do you mean on a new record, when the first date field is blank? In that case, you would add logic into the preOpen, with action === 'create', and add those fields in there.

    Colin

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Hi Colin, manage to do with change event, using the following documentation https://editor.datatables.net/reference/api/field().input()

    Enclosed the Revised Example for your feedback - can I use this way?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited June 2020

    Yep, that's a good way to go. You could also use dependent(), but yours is working nicely,

    Colin

This discussion has been closed.