Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Inline editing of foreign keys

Hi

I was wondering how easy it is to implement inline editing of module forms via a popup. For example, I have a module with
public $foreign_keys = array('imageID' => array('app' => 'images_model', 'order' => 'imageName asc'));

On the edit page, this gives me a dropdown box with [edit] & [add] buttons. When I want to say, add a new option (for that dropdown), I click the button and I get a "create" page from the images_model.

How can get that "create" page to appear as a popup? It happens elsewhere, I'm not sure how that's implemented...

TIA

cheers

Comments

  • edited 4:12AM
    There is a field type called "inline_edit" that creates that functionality:
    http://docs.getfuelcms.com/general/forms#inline_edit
  • edited 4:12AM
    That's helpful, thanks. My module also has another situation that is slightly more complicated however.

    I have some "copy" fields which are created manually in the module:
    $str = '<div>/*my manually created content*/</div><a href="'.fuel_url('my_model/create').'" class="btn_field">Add</a>'; return array('type' => 'copy', 'tag'=>'div','value' => $str, 'order' => 10);

    Is there way to get Fuel to do the popup for this "add" or do I need to code it manually with an extra 'js'=>'somejs();' parameter in my returned array?
  • edited 4:12AM
    You can try adding the class "add_edit" next to btn_field class which is what get's automatically inserted and is looked for by that inline field type. However, I haven't directly tested that.
  • <a href="'.fuel_url('my_model/create').'" class="btn_field add_edit">My Add Button</a>

    Gives me extra buttons with undefined href attributes. eg.
    [My Add Button] [Add] [Edit]

    My Add Button still opens a new page, the Add & Edit attempt to open popups but have undefined hrefs.
  • edited 4:12AM
    What if you create a select element that has a display: none and a module data attribute like so:
    <select class="add_edit" data-module="my_module" style="display: none"></select>
    Also, as an FYI, the logic for the inline_edit javascript is found in the custom_fields.js file "fuel.fields.inline_edit_field" method if you need to create your own JS logic.
  • A better solution:
    The <select> solution works but restricts the ability to pass URL parameters to the popup. For example, it's handy to pass the ID of the parent record.

    It seems the class "add_inline_button" is more useful here.

    <a href="'.fuel_url('my_model/inline_create?imageID='.$values['imageID']).'" class="btn_field add_inline_button">My Add Button</a>

    This was tested on Fuel 1.1...
  • edited 4:12AM
    Set the "module" parameter to FALSE:
    $fields['my_field']['module'] = FALSE;
Sign In or Register to comment.