在自定义修改器中选择的默认值



我有一个从如下定义的表单中选择的字段。正如您所看到的,select有两个值,Yes和No。我想为这个select设置一个默认值

"children" => [
"bc_offer_is_duration_count_fixed" => [
"arguments" => [
"data" => [
"config" => [
"dataType" => "select",
"formElement" => "select",
"visible" => "1",
"required" => "1",
"validation" => [
'required-entry' => "1"
],
"default" => null,
"label" => __('Is duration count fixed'),
"scopeLabel" => __('[GLOBAL]'),
"code" => "bc_offer_offer_durations",
"source" => "content",
"globalScope" => true,
"sortOrder" => 10,
"componentType" => "field",
"component" => "Project_OfferProducts/js/form/element/offer-is-duration-count-fixed",
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
]
]
]
]
]

它是这里定义的类的modifyData方法的一部分

use MagentoCatalogUiDataProviderProductFormModifierAbstractModifier as CatalogAbstractModifier;
abstract class AbstractModifier extends CatalogAbstractModifier

显然,我已经尝试设置"default" => "Yes""default" => "1""default" => 1

我还有一个offer-js-duration-count-fixed.js文件,其中包含内容

define([
'Magento_Ui/js/form/element/select',
'Project_OfferProducts/js/model/offer-configuration/context'
], function (Select, context) {
'use strict';
return Select.extend({
updatingDurationFromField: false,
initialize: function () {
this._super();
context.isDurationCountFixed.subscribe(function(newValue){
this.refreshInField(newValue);
}.bind(this));
this.value.subscribe(this.refreshInGrid.bind(this));
if(context.isDurationCountFixed())
{
this.value(1);
}
else
{
this.value(0);
}
return this;
},
refreshInGrid: function(){
this.updatingDurationFromField = true;
context.isDurationCountFixed(this.value());
this.updatingDurationFromField = false;
},
refreshInField: function(newValue){
if(!this.updatingDurationFromField)
{
this.value(context.isDurationCountFixed());
}
}
});});

我在马根托2号下面。

正是我所认为的

更改此

'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]

'options' => [['label' => __('Yes'), 'value' => 1], ['label' => __('No'), 'value' => 0]]

并更改

"default" => null,

"default" => "1",

相关内容

  • 没有找到相关文章

最新更新