Forums

Field Value

itpates 17 Sep, 2018
I have Form Fields set up to pre-populate with data using Model[field] for editing existing entries, and that works perfectly. I'd like to use those same Form Fields in a blank form to create a new entry. Is there a way the Value can be conditional on whether there is data to populate it so it does not display Model[field] in a new entry form. A sort of "if there is data, display it here, if there is none, display nothing." Or am I going to have to create redundant Form Fields?
GreyHead 17 Sep, 2018
Hi itpates,

Is this a ChronoConnectivity question or a ChronoForms one? I suspect the latter.

Normally ChronoForms will populate form inputs with any matching data that is in the form data when the form loads and will otherwise leave the inputs empty,

BUT sometimes you want to have slightly different ways of handling new entries and edit entries e.g. with uploaded files. In that case it can be simpler to use two forms.

Bob
itpates 17 Sep, 2018
Chronoconnectivity. But thanks.
healyhatman 18 Sep, 2018
Answer
You should be able to use the same form - if {var:read_data.model.field} is empty, the value will be empty - no pre-population. But you'll probably want to have the event that the submit button points to be different depending on if you're editing an entry or saving a new one. Maybe have a hidden "id" field and in your submit event, check if the value is empty and using a switch action call either {fn:save_data} or {fn:update_data}
itpates 21 Sep, 2018
Works perfectly. I had it with MODEL[field] because that's the way I saw it done in examples. The {var:read_data.model.field} works just as well and allows me to re-use those fields. Handy. It's not calling another database read, is it? I assume the MODEL[field] was just reading from the array returned from the single database read.

The database save function can detect between a new or a save and the ID database field is set to auto-increment if empty data is sent to it, so that works out well.
This topic is locked and no more replies can be posted.