Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTMLFormElement.addClass: Improve removal of duplicates.
It's now possible to add multiple classes as whitespace seperated string and still detect class duplicates.
- Loading branch information
Showing
4 changed files
with
61 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Widget base classes | ||
=================== | ||
|
||
HTMLFormElement | ||
--------------- | ||
|
||
addClass | ||
........ | ||
|
||
Widgets based on :code:`HTMLFormElement` also have the :code:`addClass` method which can be used to add CSS classes to the widget. | ||
:: | ||
|
||
>>> from z3c.form.browser.widget import HTMLFormElement | ||
>>> form = HTMLFormElement() | ||
|
||
The :code:`klass` attribute is used because :code:`class` is a reserved keyword in Python. | ||
It's empty per default:: | ||
|
||
>>> form.klass | ||
|
||
|
||
After adding a class it shows up in :code:`klass`:: | ||
|
||
>>> form.addClass("my-css-class") | ||
>>> form.klass | ||
'my-css-class' | ||
|
||
|
||
:code:`addClass` prevents adding the same class twice:: | ||
|
||
>>> form.addClass("my-css-class") | ||
>>> form.klass | ||
'my-css-class' | ||
|
||
>>> form.addClass("another-class") | ||
>>> form.klass | ||
'my-css-class another-class' | ||
|
||
>>> form.addClass("another-class third-class") | ||
>>> form.klass | ||
'my-css-class another-class third-class' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters