Magento 2 - Two dependencies in one field form?
It is possible to add 2 depedencies to 1 field?
Like this?
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 1'
)
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 2'
)
With this code it looks like only add the first dependency
Can i also indicate if the $field_to_show hides insteand of show?
magento2 forms magento-2.0.4 dependency
add a comment |
It is possible to add 2 depedencies to 1 field?
Like this?
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 1'
)
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 2'
)
With this code it looks like only add the first dependency
Can i also indicate if the $field_to_show hides insteand of show?
magento2 forms magento-2.0.4 dependency
add a comment |
It is possible to add 2 depedencies to 1 field?
Like this?
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 1'
)
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 2'
)
With this code it looks like only add the first dependency
Can i also indicate if the $field_to_show hides insteand of show?
magento2 forms magento-2.0.4 dependency
It is possible to add 2 depedencies to 1 field?
Like this?
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 1'
)
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 2'
)
With this code it looks like only add the first dependency
Can i also indicate if the $field_to_show hides insteand of show?
magento2 forms magento-2.0.4 dependency
magento2 forms magento-2.0.4 dependency
asked May 30 '16 at 14:41
Gianni Di FalcoGianni Di Falco
486522
486522
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
MagentoConfigModelConfigStructureElementDependencyFieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
I tried that, did not work get errorNotice: Array to string conversion
taking a look atvendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
add a comment |
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'MagentoBackendBlockWidgetFormElementDependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
New contributor
This is perfect solution
– milan Thakkar
13 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117570%2fmagento-2-two-dependencies-in-one-field-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
MagentoConfigModelConfigStructureElementDependencyFieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
I tried that, did not work get errorNotice: Array to string conversion
taking a look atvendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
add a comment |
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
MagentoConfigModelConfigStructureElementDependencyFieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
I tried that, did not work get errorNotice: Array to string conversion
taking a look atvendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
add a comment |
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
MagentoConfigModelConfigStructureElementDependencyFieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
MagentoConfigModelConfigStructureElementDependencyFieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
edited May 31 '16 at 13:44
answered May 30 '16 at 18:29
Renon StewartRenon Stewart
12.1k12044
12.1k12044
I tried that, did not work get errorNotice: Array to string conversion
taking a look atvendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
add a comment |
I tried that, did not work get errorNotice: Array to string conversion
taking a look atvendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
I tried that, did not work get error
Notice: Array to string conversion
taking a look at vendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it $this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
I tried that, did not work get error
Notice: Array to string conversion
taking a look at vendormagentomodule-backendBlockWidgetFormElementDependence.php
the first dependency gets overwritten by the seconed if a separe it $this->_depends[$fieldName][$fieldNameFrom] = $refField;
– Gianni Di Falco
May 31 '16 at 6:57
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
Wow ty for your interest, have not tried it yet but it seems it may work
– Gianni Di Falco
Jun 13 '16 at 6:49
add a comment |
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'MagentoBackendBlockWidgetFormElementDependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
New contributor
This is perfect solution
– milan Thakkar
13 mins ago
add a comment |
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'MagentoBackendBlockWidgetFormElementDependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
New contributor
This is perfect solution
– milan Thakkar
13 mins ago
add a comment |
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'MagentoBackendBlockWidgetFormElementDependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
New contributor
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'MagentoBackendBlockWidgetFormElementDependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
New contributor
New contributor
answered 13 mins ago
milan Thakkarmilan Thakkar
1
1
New contributor
New contributor
This is perfect solution
– milan Thakkar
13 mins ago
add a comment |
This is perfect solution
– milan Thakkar
13 mins ago
This is perfect solution
– milan Thakkar
13 mins ago
This is perfect solution
– milan Thakkar
13 mins ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f117570%2fmagento-2-two-dependencies-in-one-field-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown