Skip to content

Commit

Permalink
Discourage the use of setId(), encourage the use of setObjectName()
Browse files Browse the repository at this point in the history
  • Loading branch information
RockinRoel committed Dec 15, 2020
1 parent 3934299 commit d3ee790
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Wt/WObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ class WT_API WObject : public Wt::Core::observable
* in the DOM, and does not need to be unique. It will usually
* reflect the widget type or role.
*
* The object name is present in the DOM in the 'data-object-name'
* attribute.
* If a WWidget has an object name, the object name is reflected
* in the `data-object-name` attribute. You can use this to find
* widgets in JavaScript (e.g. for automated testing) using:
*
* ```
* document.querySelector('*[data-object-name="yourObjectNameHere"]')
* ```
*
* The default object name is empty (no object name).
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Wt/WWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@ class WT_API WWidget : public WObject
* letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"),
* and periods (".").
*
* \warning We recommend that you leave the id of a widget unchanged. %Wt
* uses the id to identify widgets in the JavaScript it generates,
* and this can often leads to bugs. If you do change the id, **only** change
* the id right after widget construction. However, usually
* there's a more preferable alternative, like setting the object name
* (WObject::setObjectName), or adding style classes (WWidget::addStyleClass).
*
* \sa WObject::id()
*/
virtual void setId(const std::string& id) = 0;
Expand Down

0 comments on commit d3ee790

Please sign in to comment.