3

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?

hvelarde
  • 2,875
  • 14
  • 34

4 Answers4

3

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

1

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

quyetnd
  • 589
  • 3
  • 8
  • Really weird since that worked for me. May be that you have typo on your portal_type ? Try install Product.Clouseau, then go into the context you want to disable the js and open a session. You then can try the expressions there until it worked for you. – quyetnd Nov 25 '11 at 02:42
  • 1
    This code only works when editing the content type but not when adding it: as the object still has not been created the condition is not fulfilled. – hvelarde Nov 30 '11 at 00:14
0

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.

sdupton
  • 1,869
  • 10
  • 9
0

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

Davi Lima
  • 800
  • 1
  • 6
  • 20
  • This does not work neither; it removes the javascript when adding content of whatever type and shows it when editing the object. – hvelarde Nov 30 '11 at 00:25