Skip to content

Commit

Permalink
Merge pull request #9037 from dgt41/formFields
Browse files Browse the repository at this point in the history
Regression User field is not validating
  • Loading branch information
Kubik-Rubik committed Feb 2, 2016
2 parents 7964922 + 122923c commit 5a188a8
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 117 deletions.
6 changes: 4 additions & 2 deletions administrator/components/com_users/views/users/tmpl/modal.php
Expand Up @@ -30,8 +30,10 @@
<div class="btn-group pull-left">
<button type="submit" class="btn hasTooltip" title="<?php echo JHtml::tooltipText('JSEARCH_FILTER_SUBMIT'); ?>" data-placement="bottom"><span class="icon-search"></span></button>
<button type="button" class="btn hasTooltip" title="<?php echo JHtml::tooltipText('JSEARCH_FILTER_CLEAR'); ?>" data-placement="bottom" onclick="document.getElementById('filter_search').value='';this.form.submit();"><span class="icon-remove"></span></button>
<button type="button" class="btn button-select" data-user-value="0" data-user-name="<?php echo $this->escape(JText::_('JLIB_FORM_SELECT_USER')); ?>"
data-user-field="<?php echo $this->escape($field);?>"><?php echo JText::_('JOPTION_NO_USER'); ?></button>
<?php if ($input->get('required', 0, 'INT') != 1 ) : ?>
<button type="button" class="btn button-select" data-user-value="0" data-user-name="<?php echo $this->escape(JText::_('JLIB_FORM_SELECT_USER')); ?>"
data-user-field="<?php echo $this->escape($field);?>"><?php echo JText::_('JOPTION_NO_USER'); ?></button>
<?php endif; ?>
</div>
<div class="btn-group pull-right hidden-phone">
<label for="filter_group_id" class="element-invisible"><?php echo JText::_('COM_USERS_FILTER_USER_GROUP'); ?></label>
Expand Down
Expand Up @@ -11,25 +11,41 @@

/**
* Layout variables
* ---------------------
* -----------------
* @var string $autocomplete Autocomplete attribute for the field.
* @var boolean $autofocus Is autofocus enabled?
* @var string $class Classes for the input.
* @var string $description Description of the field.
* @var boolean $disabled Is this field disabled?
* @var string $group Group the field belongs to. <fields> section in form XML.
* @var boolean $hidden Is this field hidden in the form?
* @var string $hint Placeholder for the field.
* @var string $id DOM id of the field.
* @var string $label Label of the field.
* @var string $labelclass Classes to apply to the label.
* @var boolean $multiple Does this field support multiple values?
* @var string $name Name of the input field.
* @var string $onchange Onchange attribute for the field.
* @var string $onclick Onclick attribute for the field.
* @var string $pattern Pattern (Reg Ex) of value of the form field.
* @var boolean $readonly Is this field read only?
* @var boolean $repeat Allows extensions to duplicate elements.
* @var boolean $required Is this field required?
* @var integer $size Size attribute of the input.
* @var boolean $spellcheck Spellcheck state for the form field.
* @var string $validate Validation rules to apply.
* @var string $value Value attribute of the field.
* @var array $checkedOptions Options that will be set as checked.
* @var boolean $hasValue Has this field a value assigned?
* @var array $options Options available for this field.
*
* @var string $asset The asset text
* @var string $authorField The label text
* @var integer $authorId The author id
* @var string $class The class text
* @var boolean $disabled True if field is disabled
* @var string $folder The folder text
* @var string $id The label text
* @var string $link The link text
* @var string $name The name text
* @var string $preview The preview image relative path
* @var integer $previewHeight The image preview height
* @var integer $previewWidth The image preview width
* @var string $onchange The onchange text
* @var boolean $readonly True if field is readonly
* @var integer $size The size text
* @var string $value The value text
* @var string $src The path and filename of the image
* @var string $preview The preview image relative path
* @var integer $previewHeight The image preview height
* @var integer $previewWidth The image preview width
* @var string $asset The asset text
* @var string $authorField The label text
* @var string $folder The folder text
* @var string $link The link text
*/
extract($displayData);

Expand Down
Expand Up @@ -13,26 +13,51 @@

/**
* Layout variables
* ------------------
* -----------------
* @var string $autocomplete Autocomplete attribute for the field.
* @var boolean $autofocus Is autofocus enabled?
* @var string $class Classes for the input.
* @var string $description Description of the field.
* @var boolean $disabled Is this field disabled?
* @var string $group Group the field belongs to. <fields> section in form XML.
* @var boolean $hidden Is this field hidden in the form?
* @var string $hint Placeholder for the field.
* @var string $id DOM id of the field.
* @var string $label Label of the field.
* @var string $labelclass Classes to apply to the label.
* @var boolean $multiple Does this field support multiple values?
* @var string $name Name of the input field.
* @var string $onchange Onchange attribute for the field.
* @var string $onclick Onclick attribute for the field.
* @var string $pattern Pattern (Reg Ex) of value of the form field.
* @var boolean $readonly Is this field read only?
* @var boolean $repeat Allows extensions to duplicate elements.
* @var boolean $required Is this field required?
* @var integer $size Size attribute of the input.
* @var boolean $spellcheck Spellcheck state for the form field.
* @var string $validate Validation rules to apply.
* @var string $value Value attribute of the field.
* @var array $checkedOptions Options that will be set as checked.
* @var boolean $hasValue Has this field a value assigned?
* @var array $options Options available for this field.
*
* @var string $id The DOM id of the element
* @var string $name The name of the field
* @var boolean $required The required attribute
* @var mixed $value The value of the field (user id)
* @var string $class The CSS class to apply
* @var integer $size The ize for the input element
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
* @var string $onchange The script for on change event
* @var string $userName The user name
* @var boolean $readOnly Check for field read only attribute
* @var string $userName The user name
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
*/

// Set the link for the user selection page
$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field={field-user-id}'
$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;required='
. ($required ? 1 : 0) . '&amp;field={field-user-id}'
. (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');

// Invalidate the input value if no user selected
if (JText::_('JLIB_FORM_SELECT_USER') == htmlspecialchars($userName, ENT_COMPAT, 'UTF-8'))
{
$userName = "";
}

JHtml::script('jui/fielduser.min.js', false, true, false, false, true);
?>
<?php // Create a dummy text field with the user name. ?>
Expand All @@ -47,13 +72,14 @@
>
<div class="input-append">
<input
type="text" id="<?php echo $id; ?>_name"
type="text" id="<?php echo $id; ?>"
value="<?php echo htmlspecialchars($userName, ENT_COMPAT, 'UTF-8'); ?>"
placeholder="<?php echo JText::_('JLIB_FORM_SELECT_USER'); ?>"
readonly
disabled="disabled"
class="field-user-input-name <?php echo $class ? (string) $class : ''?>"
<?php echo $size ? ' size="' . (int) $size . '"' : ''; ?>/>
<?php if (!$readOnly) : ?>
<?php echo $size ? ' size="' . (int) $size . '"' : ''; ?>
<?php echo $required ? 'required' : ''; ?>/>
<?php if (!$readonly) : ?>
<a class="btn btn-primary button-select" title="<?php echo JText::_('JLIB_FORM_CHANGE_USER') ?>"><span class="icon-user"></span></a>
<?php echo JHtml::_(
'bootstrap.renderModal',
Expand Down
51 changes: 34 additions & 17 deletions layouts/joomla/form/field/media.php
Expand Up @@ -11,24 +11,41 @@

/**
* Layout variables
* ---------------------
* -----------------
* @var string $autocomplete Autocomplete attribute for the field.
* @var boolean $autofocus Is autofocus enabled?
* @var string $class Classes for the input.
* @var string $description Description of the field.
* @var boolean $disabled Is this field disabled?
* @var string $group Group the field belongs to. <fields> section in form XML.
* @var boolean $hidden Is this field hidden in the form?
* @var string $hint Placeholder for the field.
* @var string $id DOM id of the field.
* @var string $label Label of the field.
* @var string $labelclass Classes to apply to the label.
* @var boolean $multiple Does this field support multiple values?
* @var string $name Name of the input field.
* @var string $onchange Onchange attribute for the field.
* @var string $onclick Onclick attribute for the field.
* @var string $pattern Pattern (Reg Ex) of value of the form field.
* @var boolean $readonly Is this field read only?
* @var boolean $repeat Allows extensions to duplicate elements.
* @var boolean $required Is this field required?
* @var integer $size Size attribute of the input.
* @var boolean $spellcheck Spellcheck state for the form field.
* @var string $validate Validation rules to apply.
* @var string $value Value attribute of the field.
* @var array $checkedOptions Options that will be set as checked.
* @var boolean $hasValue Has this field a value assigned?
* @var array $options Options available for this field.
*
* @var string $asset The asset text
* @var string $authorField The label text
* @var integer $authorId The author id
* @var string $class The class text
* @var boolean $disabled True if field is disabled
* @var string $folder The folder text
* @var string $id The label text
* @var string $link The link text
* @var string $name The name text
* @var string $preview The preview image relative path
* @var integer $previewHeight The image preview height
* @var integer $previewWidth The image preview width
* @var string $onchange The onchange text
* @var boolean $readonly True if field is readonly
* @var integer $size The size text
* @var string $value The value text
* @var string $preview The preview image relative path
* @var integer $previewHeight The image preview height
* @var integer $previewWidth The image preview width
* @var string $asset The asset text
* @var string $authorField The label text
* @var string $folder The folder text
* @var string $link The link text
*/
extract($displayData);

Expand Down
59 changes: 43 additions & 16 deletions layouts/joomla/form/field/user.php
Expand Up @@ -13,25 +13,50 @@

/**
* Layout variables
* ------------------
* -----------------
* @var string $autocomplete Autocomplete attribute for the field.
* @var boolean $autofocus Is autofocus enabled?
* @var string $class Classes for the input.
* @var string $description Description of the field.
* @var boolean $disabled Is this field disabled?
* @var string $group Group the field belongs to. <fields> section in form XML.
* @var boolean $hidden Is this field hidden in the form?
* @var string $hint Placeholder for the field.
* @var string $id DOM id of the field.
* @var string $label Label of the field.
* @var string $labelclass Classes to apply to the label.
* @var boolean $multiple Does this field support multiple values?
* @var string $name Name of the input field.
* @var string $onchange Onchange attribute for the field.
* @var string $onclick Onclick attribute for the field.
* @var string $pattern Pattern (Reg Ex) of value of the form field.
* @var boolean $readonly Is this field read only?
* @var boolean $repeat Allows extensions to duplicate elements.
* @var boolean $required Is this field required?
* @var integer $size Size attribute of the input.
* @var boolean $spellcheck Spellcheck state for the form field.
* @var string $validate Validation rules to apply.
* @var string $value Value attribute of the field.
* @var array $checkedOptions Options that will be set as checked.
* @var boolean $hasValue Has this field a value assigned?
* @var array $options Options available for this field.
*
* @var string $id The DOM id of the element
* @var string $name The name of the field
* @var boolean $required The required attribute
* @var mixed $value The value of the field (user id)
* @var string $class The CSS class to apply
* @var integer $size The ize for the input element
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
* @var string $onchange The script for on change event
* @var string $userName The user name
* @var boolean $readOnly Check for field read only attribute
* @var string $userName The user name
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
*/

$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $id
$link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;required='
. ($required ? 1 : 0) . '&amp;field={field-user-id}'
. (isset($groups) ? ('&amp;groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&amp;excluded=' . base64_encode(json_encode($excluded))) : '');

// Invalidate the input value if no user selected
if (JText::_('JLIB_FORM_SELECT_USER') == htmlspecialchars($userName, ENT_COMPAT, 'UTF-8'))
{
$userName = "";
}

// Load the modal behavior script.
JHtml::_('behavior.modal', 'a.modal_' . $id);

Expand All @@ -40,11 +65,13 @@
<?php // Create a dummy text field with the user name. ?>
<div class="input-append">
<input
type="text" id="<?php echo $id; ?>_name"
type="text" id="<?php echo $id; ?>"
value="<?php echo htmlspecialchars($userName, ENT_COMPAT, 'UTF-8'); ?>"
placeholder="<?php echo JText::_('JLIB_FORM_SELECT_USER'); ?>"
readonly
disabled="disabled" <?php echo $size ? ' size="' . (int) $size . '"' : ''; ?> />
<?php if (!$readOnly) : ?>
<?php echo $size ? ' size="' . (int) $size . '"' : ''; ?>
<?php echo $required ? 'required' : ''; ?>/>
<?php if (!$readonly) : ?>
<a class="btn btn-primary modal_<?php echo $id; ?>" title="<?php echo JText::_('JLIB_FORM_CHANGE_USER'); ?>" href="<?php echo $link; ?>" rel="{handler: 'iframe', size: {x: 800, y: 500}}">
<span class="icon-user"></span>
</a>
Expand Down
8 changes: 1 addition & 7 deletions libraries/cms/form/field/user.php
Expand Up @@ -92,16 +92,10 @@ public function getLayoutData()
$table->name = JText::_('JLIB_FORM_SELECT_USER');
}

// Initialize JavaScript field attributes.
$onchange = (string) $this->element['onchange'];

$extraData = array(
'onchange' => $onchange,
'userName' => $table->name,
'groups' => $this->getGroups(),
'excluded' => $this->getExcluded(),
'readOnly' => $this->readonly,
'class' => $this->class,
'excluded' => $this->getExcluded()
);

return array_merge($data, $extraData);
Expand Down
2 changes: 1 addition & 1 deletion media/jui/js/fielduser.js
Expand Up @@ -123,7 +123,7 @@ function jSelectUser(element) {
name = $el.data('user-name'),
fieldId = $el.data('user-field'),
$inputValue = jQuery('#' + fieldId + '_id'),
$inputName = jQuery('#' + fieldId + '_name');
$inputName = jQuery('#' + fieldId);

if (!$inputValue.length) {
// The input not found
Expand Down

0 comments on commit 5a188a8

Please sign in to comment.