Not a bug NumberBox "step" Validation Inconsistent with XF 1.x Behavior

pegasus

Well-known member
Affected version
2.0.12
In XenForo 2.x, the "step" parameter for spinboxes behaves differently from XF 1.x.

In XenForo 1.x, the "step" parameter allowed to +/- to skip ahead/back in pre-defined increments. If the user desired a custom value outside of those increments, it was permitted. The DataWriter never validated that a numeric option value was consistent with "step". The input element was type=text.

In XenForo 2.x, the input element used for spinboxes is now type=number. This triggers browser validation of the field, which verifies that the input value is consistent with the element's "step" attribute. However, the Option entity does not validate that numeric option values are consistent with "step", leading me to believe that the value should not be validated in this way.

In XenForo 1.x, many add-ons used the spinbox step parameter solely as a convenience so the user could jump increments quickly. If an add-on wanted to validate that the number fulfilled certain requirements, it did so using an option handler.

In XenForo 2.x, is this a bug or an intended change in behavior? I did not find any documentation of the change with a quick search. If the change is intended, might I suggest a new format parameter like soft_step or something so that we can achieve the previous behavior if desired?
 
So in the option's Format Parameters box, we should change "step" to "data-step"? From what I can tell this is not implemented by admin:option_macros in Beta 5.

If it was not clear, my report was specifically in reference to an Option's edit_format_parameters and the appropriate way to migrate them from XF 1.x to XF 2.x to achieve the same behavior. If this is not possible or is as inconvenient as below-described, then I would argue your classification of "Not a Bug" is incorrect.

Currently to use the previous behavior, in 2.1 we must:
  1. Change Edit Format from SpinBox to Callback
  2. Create unique Callback classes for each option (assuming they have different min/step/max values).
  3. Manually generate the NumberBoxRow in our callback, specifying "data-step".
This is signficantly less convenient than the previous behavior, which only required specifying a single Format Parameter to achieve the same effect.

For now, I have added the unimplemented Format Parameter "data-step" to the problematic Options instead of "step", under the assumption that admin:option_macros will implement it in the near future.
 
Last edited:
You can add the data-step attribute directly to xf:numberbox elements in templates as of XF 2.1.0 Beta 1.

You're right though, we didn't support that in option format params, but we do as of Beta 6.

You'd use stepOverride as the format param and that is passed into the data-step attribute.
 
Back
Top Bottom