Question

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?

Was it helpful?

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

OTHER TIPS

It should be python:context.portal_type!='collective.nitf.content'

Try portal_type, not meta_type with Dexterity types. All Dexterity items have the meta_type of 'Dexterity FTI.'. This also means that OFS methods filtering on meta_type will not work and you have to use list comprehensions instead.

I have tried and you can also do this:

python:context.restrictedTraverse('@@plone_interface_info').provides('your.dotted.interface.IName')

Kudos Mikko! :-) http://readthedocs.org/docs/collective-docs/en/latest/components/interfaces.html?#plone-interface-info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top