Can’t get tag pair to work for matrix.
Posted: 28 September 2010 05:36 PM   [ Ignore ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-28

I’m having some trouble getting the tag pair to work on a Matrix, according to the docs I should be using:

{your_custom_field_name}{/your_custom_field_name} 

I get nothing using this syntax.

The entry ID is being passed and I can easily edit and view other fields such as the title.

If I use the:

{field:matrix-field-name} 

I get the matrix control but the data contained in the matrix isn’t representative of what the matrix holds - it’s as if it’s an empty matrix and not what I see in the CP.

If enter some data in the data gets saved in the DB, and the new data is added to the matrix in the CP but this data is never seen in the SafeCracker output.

There are no JS errors, the template snippet is:

{exp:safecracker channel="property-db" return="view/ENTRY_ID" entry_id="{segment_2}"}
    {safecracker_head}
    
<label for="title">Title</label>
    <
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100">
    
    <
input type="text" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50" /> 

    
{field:matrix-name}    

    
<input type="submit" name="submit" value="Submit" />

{/exp:safecracker} 

EE ver 20100810
Matrix ver 2.0.11
safecracker.1.0.0.build.20100924

Any ideas?

Profile
 
 
Posted: 28 September 2010 05:38 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

{field:matrix-name} is the appropriate way to display the field. The tag pair is for DATA output, not FIELD output, if that makes sense.

Not sure why your existing data is not showing. If you add other custom fields, like a text field or something, is that data showing up on your entry form?

Profile
 
 
Posted: 28 September 2010 05:46 PM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-28

Yeah I can access and save other fields fine.

Only seems to be with the Matrix.

Looks like something to do with the indexes of the rows - it’s like it’s appending data each time I save it and then when you view it the indexes don’t match up and it’s displaying a ‘default’ matrix in the SafeCracker form.

Profile
 
 
Posted: 28 September 2010 05:47 PM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Any chance you could give me site access? PM me.

Profile
 
 
Posted: 28 September 2010 07:42 PM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I don’t think this will work, but it’s worth a shot, I suppose. Try putting your {safecracker_head} at the end of your form.

Profile
 
 
Posted: 29 September 2010 04:12 AM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-28

Doesn’t appear to have made a difference.

I’ve PM’d you some details, let me know if you need anything else.

Profile
 
 
Posted: 29 September 2010 05:46 AM   [ Ignore ]   [ # 6 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-28

Looks like this is actually an issue with more than one Matrix - with just one everything works as expected.

Add another matrix into that field group / channel and problems start to appear.

Any chance of supporting multiple matrix’s?

Profile
 
 
Posted: 29 September 2010 08:53 PM   [ Ignore ]   [ # 7 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Found the fix. Open up your /system/expressionengine/third_party/safecracker/libraries/safecracker_lib.php file.

In the display_field function around line 1240 you will find this line:

$this->EE->api_channel_fields->field_types[$this->EE->api_channel_fields->field_type]->field_name $field_name

add this line below that line

$this->EE->api_channel_fields->field_types[$this->EE->api_channel_fields->field_type]->field_id $this->get_field_id($field_name); 

resulting in:

$this->EE->api_channel_fields->field_types[$this->EE->api_channel_fields->field_type]->field_name $field_name;
        
$this->EE->api_channel_fields->field_types[$this->EE->api_channel_fields->field_type]->field_id $this->get_field_id($field_name); 
Profile
 
 
Posted: 30 September 2010 04:47 PM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-09-28

Perfect. Worked a charm.

Thanks so much.

Profile