Make WordPress Core

Opened 5 years ago

Closed 2 years ago

#48030 closed defect (bug) (fixed)

HTML5 input types are not being reset when submitting the addtag form

Reported by: stevegrunwell's profile stevegrunwell Owned by: davidbaumwald's profile davidbaumwald
Milestone: 6.0 Priority: normal
Severity: minor Version:
Component: Taxonomy Keywords: needs-testing has-patch
Focuses: ui, javascript, administration Cc:

Description (last modified by sabernhardt)

The addtag form on wp-admin/edit-tags.php automatically clears the new term's name, slug, and description field but will *not* clear any visible inputs beyond input[type="text"] and textarea.

The offending bit of code is in js/_enqueues/admin/tags.js:

$('input[type="text"]:visible, textarea:visible', form).val('');

If we broaden the scope a bit, we can hit all visible inputs but still exclude checkboxes + radios.

Attachments (4)

48030.patch (522 bytes) - added by stevegrunwell 5 years ago.
48030.2.patch (565 bytes) - added by stevegrunwell 5 years ago.
Updated version that excludes radio buttons and checkboxes.
48030.gif (152.3 KB) - added by peterwilsoncc 2 years ago.
48030.3.diff (662 bytes) - added by davidbaumwald 2 years ago.
Updated patch excluding buttons types

Download all attachments as: .zip

Change History (14)

5 years ago

5 years ago

Updated version that excludes radio buttons and checkboxes.

#1 @valentinbora
4 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to Future Release

#2 @sabernhardt
3 years ago

  • Description modified (diff)
  • Keywords needs-testing added

#3 @sabernhardt
3 years ago

  • Component changed from Administration to Taxonomy
  • Milestone changed from Future Release to 6.0

#4 @davidbaumwald
2 years ago

  • Owner set to davidbaumwald
  • Status changed from new to reviewing

#5 @davidbaumwald
2 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52953:

Taxonomy: Consider HTML5 input types when resetting form values after adding a new tag.

When adding a new tag, the form is reset by clearing values for input[type=text] and textareas. However, the reset doesn't account for any HTML5 input types, like number or url, that may be added by plugins or themes.

This change updates the form resetting jQuery to clear any values from input types that are not hidden and neither a checkbox nor radio type.

Props stevegrunwell.
Fixes #48030.

2 years ago

#6 @peterwilsoncc
2 years ago

  • Keywords needs-patch added; has-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

The selector is a little eager and removes the text from the submit button too. I've added a gif above to illustrate.

I suggest

  • include the parent div.form-field > in the selector
  • exclude button types, including submit, reset, etc.

#7 @davidbaumwald
2 years ago

Per discussion with @peterwilsoncc, including the parent in the selector would force plugins/themes to follow the same pattern to take advantage of the form reset on submission. As there's currently many plugins making use of this feature, the safe thing to do here is to omit the parent selector.

However, the buttons do need to be accounted for. Updated patch incoming. Would appreciate some additional testing to make sure we've covered the default fields while also allowing for extenders to use the feature with their added fields/buttons.

2 years ago

Updated patch excluding buttons types

#8 @davidbaumwald
2 years ago

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.

2 years ago

#10 @davidbaumwald
2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 53168:

Taxonomy: Only reset non-button form field values after adding a tag.

[52953] added HTML5 input types to the form reset after a tag is created. The selector was a bit too greedy, causing button types to have their values reset also.

This change updates the jQuery selector to exclude button, submit, and reset input types from the form reset.

Follow-up to [52953].

Props peterwilsoncc.
Fixes #48030.

Note: See TracTickets for help on using tickets.