javascriptplonedexteritygenericsetup

Removing fieldset tab interface on a Dexterity content type


I need to add a condition to avoid the load of some javascript code when adding an object of my content type; the following condition only works when editing the object:

<?xml version="1.0"?>
<object name="portal_javascripts">
 <javascript id="form_tabbing.js"
   expression="python:object.portal_type != 'collective.nitf.content'" />
</object>

This javascript code is responsible for creating the tab interface but I want to bypass it for my use case.

Any hint?


Solution

  • Actually, you can solve this in a different way.

    Instead of avoiding the load of the Javascript file -- which would have nasty consequences when it comes to caching and so.. -- you could avoid it from acting on your form.

    The *form_tabbing.js* will look for a form element with enableFormTabbing class:

    <form class="enableFormTabbing">
      <fieldset id="fieldset-[unique-id]">
        <legend id="fieldsetlegend-[same-id-as-above]">Title</legend>
      </fieldset>
    </form>
    

    So, all you need to do is avoid the form of getting this enableFormTabbing class.

    As your content type is created with Dexterity, I suggest you to override the AddForm as follows:

    class AddForm(dexterity.AddForm):
        """Default view looks like a News Item.
        """
        grok.name('collective.nitf.content')
        grok.layer(INITFBrowserLayer)
    
        enable_form_tabbing = False
    

    Thanks to plone.app.z3cform magic an enable_form_tabbing attribute will allow you to control tabbing on your form.

    The same applies to the EditForm.

    Hope that helps