diff --git a/app/code/Magento/Rule/Model/Condition/AbstractCondition.php b/app/code/Magento/Rule/Model/Condition/AbstractCondition.php index a1987f67e47f2..d2be99757df47 100644 --- a/app/code/Magento/Rule/Model/Condition/AbstractCondition.php +++ b/app/code/Magento/Rule/Model/Condition/AbstractCondition.php @@ -62,7 +62,8 @@ abstract class AbstractCondition extends \Magento\Framework\DataObject implement protected $_layout; /** - * Base name for hidden elements + * Base name for hidden elements. + * * @var string */ protected $elementName = 'rule'; @@ -116,8 +117,9 @@ public function getDefaultOperatorInputByType() } /** - * Default operator options getter - * Provides all possible operator options + * Default operator options getter. + * + * Provides all possible operator options. * * @return array */ @@ -141,6 +143,8 @@ public function getDefaultOperatorOptions() } /** + * Get rule form. + * * @return Form */ public function getForm() @@ -149,6 +153,8 @@ public function getForm() } /** + * Get condition as array. + * * @param array $arrAttributes * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -195,6 +201,8 @@ public function getMappedSqlField() } /** + * Get condition as xml. + * * @return string */ public function asXml() @@ -214,6 +222,8 @@ public function asXml() } /** + * Load condition from array. + * * @param array $arr * @return $this * @SuppressWarnings(PHPMD.NPathComplexity) @@ -229,6 +239,8 @@ public function loadArray($arr) } /** + * Load condition from xml. + * * @param string|array $xml * @return $this */ @@ -242,6 +254,8 @@ public function loadXml($xml) } /** + * Load attribute options. + * * @return $this */ public function loadAttributeOptions() @@ -250,6 +264,8 @@ public function loadAttributeOptions() } /** + * Get attribute options. + * * @return array */ public function getAttributeOptions() @@ -258,6 +274,8 @@ public function getAttributeOptions() } /** + * Get attribute select options. + * * @return array */ public function getAttributeSelectOptions() @@ -270,6 +288,8 @@ public function getAttributeSelectOptions() } /** + * Get attribute name. + * * @return string */ public function getAttributeName() @@ -278,6 +298,8 @@ public function getAttributeName() } /** + * Load operator options. + * * @return $this */ public function loadOperatorOptions() @@ -300,6 +322,8 @@ public function getInputType() } /** + * Get operator select options. + * * @return array */ public function getOperatorSelectOptions() @@ -316,6 +340,8 @@ public function getOperatorSelectOptions() } /** + * Get operator name. + * * @return array */ public function getOperatorName() @@ -324,6 +350,8 @@ public function getOperatorName() } /** + * Load value options. + * * @return $this */ public function loadValueOptions() @@ -333,6 +361,8 @@ public function loadValueOptions() } /** + * Get value select options. + * * @return array */ public function getValueSelectOptions() @@ -380,6 +410,8 @@ public function isArrayOperatorType() } /** + * Get value. + * * @return mixed */ public function getValue() @@ -395,6 +427,8 @@ public function getValue() } /** + * Get value name. + * * @return array|string * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ @@ -446,6 +480,8 @@ public function getNewChildSelectOptions() } /** + * Get new child name. + * * @return string */ public function getNewChildName() @@ -454,6 +490,8 @@ public function getNewChildName() } /** + * Get this condition as html. + * * @return string */ public function asHtml() @@ -467,6 +505,8 @@ public function asHtml() } /** + * Get this condition with subconditions as html. + * * @return string */ public function asHtmlRecursive() @@ -475,6 +515,8 @@ public function asHtmlRecursive() } /** + * Get type element. + * * @return AbstractElement */ public function getTypeElement() @@ -493,6 +535,8 @@ public function getTypeElement() } /** + * Get type element html. + * * @return string */ public function getTypeElementHtml() @@ -501,6 +545,8 @@ public function getTypeElementHtml() } /** + * Get attribute element. + * * @return $this */ public function getAttributeElement() @@ -528,6 +574,8 @@ public function getAttributeElement() } /** + * Get attribute element html. + * * @return string */ public function getAttributeElementHtml() @@ -536,8 +584,9 @@ public function getAttributeElementHtml() } /** - * Retrieve Condition Operator element Instance - * If the operator value is empty - define first available operator value as default + * Retrieve Condition Operator element Instance. + * + * If the operator value is empty - define first available operator value as default. * * @return \Magento\Framework\Data\Form\Element\Select */ @@ -568,6 +617,8 @@ public function getOperatorElement() } /** + * Get operator element html. + * * @return string */ public function getOperatorElementHtml() @@ -587,6 +638,8 @@ public function getValueElementType() } /** + * Get value element renderer. + * * @return \Magento\Rule\Block\Editable */ public function getValueElementRenderer() @@ -598,6 +651,8 @@ public function getValueElementRenderer() } /** + * Get value element. + * * @return $this */ public function getValueElement() @@ -615,6 +670,9 @@ public function getValueElement() // date format intentionally hard-coded $elementParams['input_format'] = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; $elementParams['date_format'] = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; + $elementParams['placeholder'] = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; + $elementParams['autocomplete'] = 'off'; + $elementParams['readonly'] = 'true'; } return $this->getForm()->addField( $this->getPrefix() . '__' . $this->getId() . '__value', @@ -626,6 +684,8 @@ public function getValueElement() } /** + * Get value element html. + * * @return string */ public function getValueElementHtml() @@ -634,6 +694,8 @@ public function getValueElementHtml() } /** + * Get add link html. + * * @return string */ public function getAddLinkHtml() @@ -643,6 +705,8 @@ public function getAddLinkHtml() } /** + * Get remove link html. + * * @return string */ public function getRemoveLinkHtml() @@ -655,6 +719,8 @@ public function getRemoveLinkHtml() } /** + * Get chooser container html. + * * @return string */ public function getChooserContainerHtml() @@ -664,6 +730,8 @@ public function getChooserContainerHtml() } /** + * Get this condition as string. + * * @param string $format * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -674,6 +742,8 @@ public function asString($format = '') } /** + * Get this condition with subconditions as string. + * * @param int $level * @return string */ @@ -816,6 +886,8 @@ protected function _compareValues($validatedValue, $value, $strict = true) } /** + * Validate model. + * * @param \Magento\Framework\Model\AbstractModel $model * @return bool */ diff --git a/app/code/Magento/Rule/view/adminhtml/web/rules.js b/app/code/Magento/Rule/view/adminhtml/web/rules.js index b094b9818364a..8e36562ebd7fe 100644 --- a/app/code/Magento/Rule/view/adminhtml/web/rules.js +++ b/app/code/Magento/Rule/view/adminhtml/web/rules.js @@ -220,6 +220,8 @@ define([ var elem = Element.down(elemContainer, 'input.input-text'); + jQuery(elem).trigger('contentUpdated'); + if (elem) { elem.focus(); diff --git a/app/design/adminhtml/Magento/backend/web/css/styles-old.less b/app/design/adminhtml/Magento/backend/web/css/styles-old.less index 26381367c72f5..dde4dafeeed23 100644 --- a/app/design/adminhtml/Magento/backend/web/css/styles-old.less +++ b/app/design/adminhtml/Magento/backend/web/css/styles-old.less @@ -3845,6 +3845,26 @@ .rule-param-edit .element { display: inline; + position: relative; + } + + .rule-param-edit .element input.input-date, + .rule-param-edit .element input.input-date[readonly] { + background-color: @color-white; + min-width: 140px; + width: 140px !important; + cursor: pointer; + text-align: center; + opacity: 1; + margin-right: 10px; + padding-right: 40px; + + + .ui-datepicker-trigger { + position: absolute; + width: 140px; + text-align: right; + left: 0; + } } .rule-param-edit .element .addafter { diff --git a/dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php b/dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php index d1fd351302414..6dbf2b1aa6a12 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php +++ b/dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php @@ -6,9 +6,9 @@ namespace Magento\Mtf\Client\Element; -use Magento\Mtf\ObjectManager; -use Magento\Mtf\Client\Locator; use Magento\Mtf\Client\ElementInterface; +use Magento\Mtf\Client\Locator; +use Magento\Mtf\ObjectManager; /** * Typified element class for conditions. @@ -135,6 +135,13 @@ class ConditionsElement extends SimpleElement */ protected $chooserGridLocator = 'div[id*=chooser]'; + /** + * Datepicker xpath. + * + * @var string + */ + private $datepicker = './/*[contains(@class,"ui-datepicker-trigger")]'; + /** * Key of last find param. * @@ -189,10 +196,7 @@ class ConditionsElement extends SimpleElement protected $exception; /** - * Set value to conditions. - * - * @param string $value - * @return void + * @inheritdoc */ public function setValue($value) { @@ -411,7 +415,16 @@ protected function fillText($rule, ElementInterface $param) { $value = $param->find('input', Locator::SELECTOR_TAG_NAME); if ($value->isVisible()) { - $value->setValue($rule); + if (!$value->getAttribute('readonly')) { + $value->setValue($rule); + } else { + $datepicker = $param->find( + $this->datepicker, + Locator::SELECTOR_XPATH, + DatepickerElement::class + ); + $datepicker->setValue($rule); + } $apply = $param->find('.//*[@class="rule-param-apply"]', Locator::SELECTOR_XPATH); if ($apply->isVisible()) { diff --git a/dev/tests/functional/lib/Magento/Mtf/Client/Element/DatepickerElement.php b/dev/tests/functional/lib/Magento/Mtf/Client/Element/DatepickerElement.php index a0e350cb3da43..eb277c2cc43dd 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Client/Element/DatepickerElement.php +++ b/dev/tests/functional/lib/Magento/Mtf/Client/Element/DatepickerElement.php @@ -66,13 +66,16 @@ public function setValue($value) $date = $this->parseDate($value); $date[1] = ltrim($date[1], '0'); $this->click(); - $this->find($this->datePickerButton, Locator::SELECTOR_XPATH)->click(); $datapicker = $this->find($this->datePickerBlock, Locator::SELECTOR_XPATH); + $datepickerClose = $datapicker->find($this->datePickerButtonClose, Locator::SELECTOR_XPATH); + if (!$datepickerClose->isVisible()) { + $this->find($this->datePickerButton, Locator::SELECTOR_XPATH)->click(); + } $datapicker->find($this->datePickerYear, Locator::SELECTOR_XPATH, 'select')->setValue($date[2]); $datapicker->find($this->datePickerMonth, Locator::SELECTOR_XPATH, 'select')->setValue($date[0]); $datapicker->find(sprintf($this->datePickerCalendar, $date[1]), Locator::SELECTOR_XPATH)->click(); if ($datapicker->isVisible()) { - $datapicker->find($this->datePickerButtonClose, Locator::SELECTOR_XPATH)->click(); + $datepickerClose->click(); } } diff --git a/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php b/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php index a8451e43ade20..3638ff921fa9d 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/AbstractElement.php @@ -201,6 +201,8 @@ public function setType($type) } /** + * Set form. + * * @param AbstractForm $form * @return $this */ @@ -238,6 +240,7 @@ public function getHtmlAttributes() 'onchange', 'disabled', 'readonly', + 'autocomplete', 'tabindex', 'placeholder', 'data-form-part', @@ -326,6 +329,8 @@ public function getRenderer() } /** + * Get Ui Id. + * * @param null|string $suffix * @return string */ diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Date.php b/lib/internal/Magento/Framework/Data/Form/Element/Date.php index c519ecfed4c82..897617e560be5 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Date.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Date.php @@ -151,7 +151,7 @@ public function getValueInstance() */ public function getElementHtml() { - $this->addClass('admin__control-text input-text'); + $this->addClass('admin__control-text input-text input-date'); $dateFormat = $this->getDateFormat() ?: $this->getFormat(); $timeFormat = $this->getTimeFormat(); if (empty($dateFormat)) { diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/AbstractElementTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/AbstractElementTest.php index e29b1dcf441e4..a85c1f4aa450c 100644 --- a/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/AbstractElementTest.php +++ b/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/AbstractElementTest.php @@ -195,6 +195,7 @@ public function testGetHtmlAttributes() 'onchange', 'disabled', 'readonly', + 'autocomplete', 'tabindex', 'placeholder', 'data-form-part', diff --git a/lib/web/mage/calendar.js b/lib/web/mage/calendar.js index ac154b333801d..a9ccf2cf787f9 100644 --- a/lib/web/mage/calendar.js +++ b/lib/web/mage/calendar.js @@ -66,6 +66,9 @@ * Widget calendar */ $.widget('mage.calendar', { + options: { + autoComplete: true + }, /** * Merge global options with options passed to widget invoke @@ -379,6 +382,9 @@ .addClass('v-middle') .text('') // Remove jQuery UI datepicker generated image .append('' + pickerButtonText + ''); + + $(element).attr('autocomplete', this.options.autoComplete ? 'on' : 'off'); + this._setCurrentDate(element); },