New form inside editortemplate in backend

Topics: General, Writing modules
Dec 6, 2011 at 8:51 PM

Is it possible to create a form which posts values to a adminController within a part editortemplate? i've tried to do this but my form is not visible in the generated html. I think this happens because there form elements get nested.

Is there a other possibility or how can i fix this problem?

Developer
Dec 6, 2011 at 9:12 PM

What are you wanting to achieve? Since you would be nesting forms, unless you build the editor (which you don't do here) you can't do that: editors for parts that the drivers build can't contain forms for the admin area, because they are automatically surrounded by one.

Dec 6, 2011 at 9:23 PM

You can't nest another <form> tag because, as you probably guessed, it's invalid HTML.

However it is possible to nest additional editor templates. You just have to collect the data in your driver, and make sure you use Prefix so all your field names are unique.

My Origami module has an advanced display builder which is designed for more complex form hierarchies. For instance when you edit a content item in Mechanics, there's a mini form to edit each relationship, but it's actually still part of the one big form, kind of webforms style.

Dec 6, 2011 at 9:23 PM

yes but that's exactly the problem. i think i have to change the code so it's using ajax to call my custom controller.

Dec 6, 2011 at 9:26 PM

What can you do from a controller that you can't do from a driver?

The other way would be to push the template directly to Layout so it's outside the content form (i.e. WorkContext.Layout.Content.Add(shapeHelper.EditorTemplate(...))). Failing that, iframes or ajax.

Dec 7, 2011 at 8:46 AM

ah. now i see you can do the same with a driver instead using a controller. But with a controller it's easier because i want to manage relationships within this form. You can do things like update, delete add relations to the current content item.

an example of how to delete a relationsship a driver instead of using a controller:

click on a delete button for a relationship and set a hidden field with javascript so you can check this hidden field in the driver, right?

is this the way you have to this kinds of things or is there a better way? thanks!

Dec 7, 2011 at 2:16 PM
Edited Dec 7, 2011 at 2:16 PM
Znowman wrote:

ah. now i see you can do the same with a driver instead using a controller. But with a controller it's easier because i want to manage relationships within this form. You can do things like update, delete add relations to the current content item.

an example of how to delete a relationsship a driver instead of using a controller:

click on a delete button for a relationship and set a hidden field with javascript so you can check this hidden field in the driver, right?

is this the way you have to this kinds of things or is there a better way? thanks!

I already have exactly this relations management in Mechanics (update, delete, add) :)  - and it's all done from the one editor form. For delete I have a checkbox on each relationship, and a drop-down to select the bulk action, and in the driver I just look for those; so it happens when the usual Save or Publish buttons. For add I have a drop-down or a list of checkboxes for which items to add. Finally I also run through a list of the relations and apply a prefix so I can apply a model update for each, this allows actual bulk edit of content items; their titles, sequence numbers, etc. Eventually I'll be using ajax to make the process smoother. It sounds like you might actually be trying to replicate some functionality I've already got working (and yeah, it wasn't easy to do it any other way...)