Forums

reload form to edit record problems

emmexx 17 Nov, 2017
I don't understand the inner workings of cfv6 when loading a form to edit a record. In previous versions it was pretty straight forward. Now I'm disappointed, probably my fault, because I don't see a consistent way to access the record data.

I followed the manual and used a Read Data action to load a record (First matching record, model name: myRecord).
In the Display Section action Data provider -> {var:read_data20.myRecord}.
Now I expected to find the record data in the data object (the old style: $this->data) but...
In an HTML object in the designer I put:
{data.pr:myRecord}
<?php pr($this->data); ?>
<?php pr($this->data['myRecord']); ?>

The 1st line prints nothing.
The 2nd one prints
    [option] => com_chronoforms6
    [chronoform] => evento
    ...

but not my record data.
The 3rd one gives an undefined index: myRecord.
Anyway some of the fields (let's say the standard input elements) are populated. Other elements are not.
E.g.:
- in a Calendar in the html code I can see that the value attribute is assigned but the displayed input element is blank.
In the properties of the calendar I added something to the Value property.
{data:myRecord.myDataField} or {var:read_data20.myRecord.myDataField} do not work, the calendar is still empty.
- in a repeater I expected to use something like {data:myRecord.myrepeaterField} as a Data Provider, but I found out I had to use {var:read_data20.myRecord.myrepeaterField}.
- It is very simple to json encode the repeater values (Save Data action in Data override on Insert):
myrepeaterField:{data.jsonen:myrepeaterField}, but json decode it in the read data action is very different, the only working solution I found is a php action with the following code:
$this->set("read_data20.myRecord.myrepeaterField", json_decode($this->get("read_data20.myRecord.myrepeaterField"), true));

Since all that messes up the code and simplicity of cf, there must be something I'm doing wrong or that I don't understand.
Can somebody help?

Thank you
maxx
emmexx 17 Nov, 2017


- in a Calendar in the html code I can see that the value attribute is assigned but the displayed input element is blank.



Trying to solve the calendar problem I tried to set the values using javascript. The problem is that the calendar seems to be initialised after the jQuery ready event.

I put my code in the ready event:

jQuery("#mycalendar").calendar('set date', '2017-12-25');


I put a breakpoint at that line and one at the libraries/cegcore2/xyz.js file

				$(calfield).closest('.field').calendar({
					startMode : $(calfield).data('startmode'),
					type : $(calfield).data('type'),


The code stops 1st at my code and then at the cegcore2 code.

Is that right?

maxx
emmexx 17 Nov, 2017

Anyway some of the fields (let's say the standard input elements) are populated. Other elements are not.


I didn't list checkboxes and found out the answer in the ccv6 forum 🙄



If you want to reload a checkboxes field you have to list the field in the Special fields attribute of the Read Data action. Use the following format:

fieldName/json

Not in the manual... :mrgreen:

maxx
emmexx 17 Nov, 2017
Answer
1 Likes
And my previous reply about checkboxes answers my other question:

- It is very simple to json encode the repeater values (Save Data action in Data override on Insert):
myrepeaterField:{data.jsonen:myrepeaterField}, but json decode it in the read data action is very different, the only working solution I found is a php action with the following code:
$this->set("read_data20.myRecord.myrepeaterField", json_decode($this->get("read_data20.myRecord.myrepeaterField"), true));



maxx
This topic is locked and no more replies can be posted.