Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept custom min and step attributes for Number field type. #229

Closed
wants to merge 1 commit into from

Conversation

ipokkel
Copy link
Member

@ipokkel ipokkel commented Dec 15, 2021

All Submissions:

Changes proposed in this Pull Request:

Remove the hardcoded default min and step attributes set and add them as html_attributes.

Resolves #227

How to test the changes in this Pull Request:

  1. Create a code snippet for the site that creates a number field and add min and step to the html_attributes option.
$fields[] = new PMProRH_Field(
	'test_number_min_step', // input field name, used as meta key
	'number',         // field type
	array(
		'label'           => 'Number Test', // display custom label, if not used field name will be used
		'html_attributes' => array(
			'min'  => '5',
			'step' => '5',
		), // add valid html input field attributes
		'hint'            => 'This is a test of html attributes for a number field', // display a hint under field
		'profile'         => true, // show on profile
	)
);
  1. Navigate to the Membership Checkout page on the frontend.
  2. Inspect rendered HTML for the number field.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

BUGFIX/ENHANCEMENT: Accept custom "step" and "min" HTML attributes set in the "html_attributes" option.

Copy link
Contributor

@ZebulanStanphill ZebulanStanphill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been running into this bug lately and only just now managed to track down what was going on. This PR looks good to merge, though I think the code could be simplified a bit.

@kimcoleman Could this be merged soon?

Comment on lines +396 to +411
if ( ! empty( $this->html_attributes ) ) {
// If custom values not available set the defaults
if ( ! array_key_exists( 'min', $this->html_attributes ) ) {
$this->html_attributes['min'] = '0';
}
if ( ! array_key_exists( 'step', $this->html_attributes ) ) {
$this->html_attributes['step'] = '1';
}
$r .= $this->getHTMLAttributes();
$r .= ' />';
} else {
// Set the defaults
$this->html_attributes['min'] = '0';
$this->html_attributes['step'] = '1';
$r .= $this->getHTMLAttributes();
}
$r .= ' />';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified:

				if ( empty( $this->html_attributes ) ) {
					$this->html_attributes = array();
				}
				// If no custom min/step is set, use defaults.
				if ( ! array_key_exists( 'min', $this->html_attributes ) ) {
					$this->html_attributes['min'] = 0;
				}
				if ( ! array_key_exists( 'step', $this->html_attributes ) ) {
					$this->html_attributes['step'] = 1;
				}
				$r .= $this->getHTMLAttributes();
				$r .= ' />';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Merging this version into core PMPro.

@ideadude
Copy link
Member

Merged into PMPro core here: strangerstudios/paid-memberships-pro@babf81e

Thanks!

@ideadude ideadude closed this Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set custom HTML attributes for the min and step attributes
3 participants