Dave

matrix + wygwam + safecracker questions

Hi Brandon,

Have searched your forums for a while to try and figure this out but still a bit stuck.

Basically, instead of using field:matrix_field in safecracker, I'm doing it manually (as per a thread I found here). Its basically working, with simple text inputs, but a couple of issues:

1 - I have a channel entries loop to show/edit the existing matrix rows, and a form to add a new row. The thing is, whenever i submit (eg. if I'm editing an existing row), it adds this new row, even if its blank. Any way to prevent this behaviour? Or do I just need to use JS to only show the new row form if they click a button.

2 - One of my matrix cols is a wygwam field. I can show the field as a textarea fine, but what do I need to do to turn it into a wygwam field?

Thanks!
Dave
1 person has
this question
+1
Reply

  • Dave
    Also, I'm using your matrix url_title fieldtype. This seems to only work with javascript, is there no way it can generate the url title from the post data instead? Ideally I want it to be generated automatically in the safecracker form, without the user having to see it at all. I would have thought it would work by taking the title field and generating the url title, after you submit the safecracker form. Any way to hide this column on the publish page?

    Sorry about all the questions! Just may as well get it sorted in one hit :-)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Hi Dave,

    Matrix will save whatever rows are submitted, whether they have data or not. So yeah, you should only add a new row to it if you intend on it getting saved.

    Getting Wygwam to initialize might be a little complicated, but essentially it boils down to:


    1. Load themes/third_party/wygwam/lib/ckeditor/ckeditor.js on the page

    2. Each time a new row is created, give its Wygwam textarea a unique ID and call CKEDITOR.replace(unique_id)



    CKEditor's Integration docs should be helpful: http://docs.cksource.com/CKEditor_3.x...

    Note that Wygwam doesn't come with the default "Kama" skin, only its custom skin. So you'll either need to pass in {skin:'wygawm2'} as a second parameter to CKEditor.replace(), or download CKEditor and copy over the skins/kama/ folder into themes/third_party/wygwam/lib/ckeditor/skins/.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Dave
    Thanks, wygwam working perfectly now. I just copied the wygwam JS that was automatically added as part of safecracker. Is it possible to initialize it with a class rather that an ID though?

    Still haven't worked out how to get the matrix url title working though - any ideas? Tried including the matrix_url_title.js file but looks like its only meant to work inside matrix.

    Cheers,
    Dave
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Sorry no, CKEDITOR.replace() requires an ID.

    For the URL titles, maybe your best bet is to just hack up MUT, and port the JS code into PHP, placing it in the fieldtype's post_save_cell() function.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Dave
    Ok thanks brandon, will give that a go. Definitely a pretty non-standard use of Matrix I'm working on!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited