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

setControlsDisplayRules opposite behaviour #2129

Closed
bedengler opened this issue Nov 11, 2023 · 8 comments
Closed

setControlsDisplayRules opposite behaviour #2129

bedengler opened this issue Nov 11, 2023 · 8 comments

Comments

@bedengler
Copy link
Contributor

Strange behaviour of setControlsDisplayRules in v3.1

// This is a Lookup field
$adspaceSelection = $form->addControl('acpos_Adspace_ID', ['id' => 'adspaceSelection']);

$group1 = $form->addGroup();
// This is a Lookup field
$productSelection = $group1->addControl('acpos_Product_ID', ['id' => 'productSelection']);

$group2 = $form->addGroup();
// This is a Line field
$quantity = $group2->addControl('acpos_Quantity', ['id' => 'acpos_Quantity']);

$form->setControlsDisplayRules([
		    'acpos_Quantity' => ['acpos_Product_ID' => 'not[empty]', 'acpos_Adspace_ID' => 'empty'],
		]);

Expected behaviour: acpos_Quantity is shown, when acpos_Product_ID has a selection and acpos_Adspace_ID not.
Real behaviour: exactly the other way round. So when acpos_Product_ID is empty and acpos_Adspace_ID has a selection, acpos_Quantity is shown.

When I do

$form->setControlsDisplayRules([
		    'acpos_Quantity' => ['acpos_Product_ID' => 'empty', 'acpos_Adspace_ID' => 'not[empty]'],
		]);

the result is the one I initially wanted, but it's against the logic...

Is the error in me, atk4 or FomanticUI? 🤪

@mvorisek
Copy link
Member

In Fomantic-UI docs I found https://fomantic-ui.com/behaviors/form.html#/examples

  • empty is used there to "not pass an empty input"
  • minLength[100] is used there to "require min. length of 100 characters"
  • is[dog] to "require the input to be "dog""

So the meaning of empty is confusing and in reality, it should be named as notEmpty.

Is this how atk4/ui behave, anything to fix here?

To confirm, can you please test with is[dog] and not[is[dog]] to confirm?

@mvorisek
Copy link
Member

kindly remainder @bedengler

@bedengler
Copy link
Contributor Author

bedengler commented Nov 17, 2023

Where did you see the definition "empty is used there to "not pass an empty input""?
According to the definition of FomanticUI, "empty" really means empty (which is logical).
See here: https://fomantic-ui.com/behaviors/form.html#empty

Tested it with is[dog] etc. and that works as expected...

I also asked in the FomanticUI Discord now, if they know about that issue or even if this IS an issue 🤪
waiting for their reply...

@mvorisek
Copy link
Member

Where did you see the definition "empty is used there to "not pass an empty input""? According to the definition of FomanticUI, "empty" really means empty (which is logical). See here: https://fomantic-ui.com/behaviors/form.html#empty

see the first code example in that link, and compare empty and checked there - empty is checking "if not empty" and checked "if checked"

@bedengler
Copy link
Contributor Author

bedengler commented Nov 17, 2023

Alright, got confirmation from FomanticUI, it's the (wrong) behaviour since SemanticUI. So it's a "bug" they are carrying on and on.
They pointed me to an article and look what I've found there: @mvorisek asking for the change from "empty" to "notEmpty" 🤪
fomantic/Fomantic-UI#2407 (comment)

It seems, they will not change that soon. Therefore I suggest 2 options:

  1. transforming "empty" to "not[empty]" and "not[empty]" to "empty" on atk4 side. That way we are flexible and independent of FomanticUI
    OR
  2. Adding a big notice about the behaviour in 1) the documentation, 2) the demos, 3) the source code of setControlsDisplayRules

What do you think should we do?

@mvorisek
Copy link
Member

I have opened fomantic/Fomantic-UI#2937 in Fomantic-UI. We should not try to fix every issue in atk4/ui, but instead support Fomantic-UI as much as possible.

@mvorisek
Copy link
Member

mvorisek commented Dec 1, 2023

Reopening as after it will be fixed by Fomantic UI, we can rename the empty usages in atk4/ui.

@mvorisek
Copy link
Member

mvorisek commented Dec 4, 2023

Since v1.5 - https://github.com/atk4/ui/blob/2.4.0/js/src/services/form.service.js#L40 - the notEmpty was already provided by atk4/ui, now it is provided officially.

@mvorisek mvorisek closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants