Is it possible to have form fields for particular rows in matrix?
Posted: 02 December 2010 04:23 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

Hi,

I’ve got {field:my_custom_matrix_field} working right, but what I really need to be able to do is edit just a particular row of the matrix, not the whole thing. Basically, instead of just duplicating the matrix field type from the control panel on the entry form, I was hoping to cycle through my matrix and display a customized form with only one particular row in the matrix that’s actually editable (actually, only one particular cell in that row). The rest of the fields would be formatted with regular formatting as I would do normally in EE, and I imagine I would maybe need to hide their values in hidden fields somewhere possibly to be submitted with the form.

Any idea if this is possible? Or maybe I need to adjust my thinking on it?

Thanks!

Profile
 
 
Posted: 02 December 2010 04:34 AM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Hi Dave,

One of the features we have is, when editing an entry, if there are fields that are not present in your entry form, those values will be preserved. So you wouldn’t need to have hidden fields for those.

But, I think the hidden fields route is what you’d have to do with your Matrix (this is off the top of my head):

{your_matrix_field}
{
!-- I only want to edit the 2nd row --}
    {if count 
== 2}
    {
!-- I only want to edit col 3--}
    
<input type="hidden" name="your_matrix_field[row_id_{row_id}][col_id_1]" value="{your_col_name_1}" />
    <
input type="hidden" name="your_matrix_field[row_id_{row_id}][col_id_2]" value="{your_col_name_3}" />
    <
input type="text" name="your_matrix_field[row_id_{row_id}][col_id_3]" value="{your_col_name_3}" />
    
{if:else}
{
!--scroll thru all your colsmake sure to look up the right col_id for each--}
    
<input type="hidden" name="your_matrix_field[row_id_{row_id}][col_id_1]" value="{your_col_name_1}" />
    <
input type="hidden" name="your_matrix_field[row_id_{row_id}][col_id_2]" value="{your_col_name_2}" />
    <
input type="hidden" name="your_matrix_field[row_id_{row_id}][col_id_3]" value="{your_col_name_3}" />
    
{/if}
{
/your_matrix_field} 

You will obviously have to tweak it some, and this is experimental, I’m not entirely sure it will work, but hopefully it’s a good head start for you.

Profile
 
 
Posted: 02 December 2010 04:56 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

Thanks Rob! Lightning fast response too! =)

This definitely looks right. I was getting a feeling of dread over how to do this, but I do believe this may just do the trick. I’ll let you know if it works out correctly. And it occurs to me also I can look at the generated html of the matrix from the {field:my_matrix_field} and just recreate the form manually.

Thanks for the quick help =)

Profile
 
 
Posted: 08 December 2010 07:29 PM   [ Ignore ]   [ # 3 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

This seems to be working really well. THe row_order array and everything works great!

I did notice a hidden field in the matrix and I’m not sure what value to put in there.

[col_id_1] is a playa field within the matrix. This is the form as generated by the field tag, (which I’m generating manually with the regular channel entries tag)

<input type="hidden" name="my_matrix[row_id_4][col_id_1][old]" value="[7] Analytics"/>
<
select name="my_matrix[row_id_4][col_id_1][selections][]">
    <
option value="">--</option>
    <
option value="11">Amazon</option>
    <
option value="12" selected="selected">Analytics</option>
    <
option value="13">Basecamp</option>
</
select

In the select box I see the entry_id and titles of the channel entries my playa field is referencing. So I have no problem assigning the correct value to a hidden field for that. However, I can’t figure out where the value for “my_matrix[row_id_4][col_id_1][old]” is from (”[7] Analytics”). Analytics is the entry title, but the number 7 is not the id. You can see the id is 12. I can’t figure out where Matrix is getting the number 7 from.

The matrix seems to update just fine if I don’t include the “[old]”  value in the form. But I wonder what that value is for and where it’s getting it from.

Profile
 
 
Posted: 08 December 2010 08:19 PM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

I believe that 7 is the rel_id from the exp_relationships table, you might need a custom sql query to retrieve that value.

Profile
 
 
Posted: 11 December 2010 02:20 AM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

ok, I’ve got one more question. I’ve been able to create the matrix form and submit it successfully. It seems to be working pretty well! One hangup I have though is in how to delete a row in the matrix. I tried simply using jQuery’s .remove to remove the list item that contained the hidden fields with the info for that row from the DOM, so I assumed when the form was submitted, with those values missing, that row would be dropped. But that turned out not to be the case. I tried inspecting the generated form to determine how rows were deleted. It must be changing some value in the form somewhere but I can’t seem to find it.

Profile
 
 
Posted: 11 December 2010 02:35 AM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Looks like you have to add a hidden input:

<input name="news_items[deleted_rows][]" type="hidden" value="row_id_XX" /> 
Profile
 
 
Posted: 11 December 2010 03:17 AM   [ Ignore ]   [ # 7 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

thanks again rob!! =D

Profile