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

[5.3] Integer custom field to be numerical input instead of a drop-down #43697

Open
wants to merge 5 commits into
base: 5.3-dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unused use
  • Loading branch information
sakiss committed Jun 24, 2024
commit eb9d1e4c23155e30a4de54381a8d0e1166e248e6
59 changes: 59 additions & 0 deletions libraries/src/Form/Field/IntegerField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Form\Field;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Form Field class for the Joomla Platform.
* Provides a select list of integers with specified first, last and step values.
*
* @since 1.7.0
*/
class IntegerField extends NumberField
{
/**
* The form field type.
*
* @var string
* @since 1.7.0
*/
protected $type = 'Integer';

/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 5.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);

if ($return) {
// It is better not to force any default limits if none is specified
$this->max = isset($this->element['last']) ? (float) $this->element['last'] : null;
$this->min = isset($this->element['first']) ? (float) $this->element['first'] : null;
$this->step = isset($this->element['step']) && (int) $this->element['step'] > 0 ? (int) $this->element['step'] : 1;
}

return $return;
}
}