2

I have a dexterity based content type with different edit views and fieldsets defined in the schema. Whenever I want to update a widget/field in another than the first fieldset, it gets crumpy. For example:

self.groups[0].fields['my_field'].mode = HIDDEN_MODE

must be used to hide my_field from the 2nd fieldset. To make the same field required

self.schema['my_field'].required = True

does the trick.

But how can I add a css class to a widget on another than the first fieldset? I mean, what

self.fields['my_field_on_first_fieldset'].widget.addClass("myClass")

would do, if my widget would be on the first fieldset "page".

7
  • What happens, when you apply the suggested line?
    – Ida
    Mar 14, 2013 at 6:57
  • Which "suggested" line?
    – user657127
    Mar 16, 2013 at 12:36
  • The last one. You are asking what it would do, I was wondering why you don't just try and see...
    – Ida
    Mar 18, 2013 at 7:31
  • Maybe I was unclear here. I know, what the line does, but I am looking for the loc that does add a class on a different than the first fieldset. See title.
    – user657127
    Mar 18, 2013 at 9:00
  • Could you clarify your quest, then? Frankly. to me it's a confusing mix of topics (hidden-mode, set-required and add-class). You could f.e. post a line, which you expect to work and tell us what happens instead. Just a suggestion :-)
    – Ida
    Mar 18, 2013 at 9:16

1 Answer 1

2

Following Martin Aspeli's tutorial, I tested your request and can confirm that oddly the klass-attribute cannot be applied on invisible widgets in the sub-fieldsets, returning a 'Key Error' in reference to the widget's name.

With other attributes, f.e. 'size', there is no problem.

Instead you can apply the class via Javascript.

If you want to provide a fallback in case the client hasn't Javascript enabled, you can add a condition in updateWidget(), checking if it is enabled and if not, apply the class with addClass() respectively the klass-attribute. Which will work then, because all fields are shown and not hidden anymore.

2
  • Thanks, I surfed around this by changing the form id by defining an id property for all my sub-forms, so that I could conditionally style my forms. But thanks for the investigation. Never intended to confuse one.
    – user657127
    Mar 21, 2013 at 11:43
  • No prob, glad you found a solution :) If you feel motivated, you could file a report at z3c.form's repo on github... Best, i.
    – Ida
    Mar 21, 2013 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.