rasteiner / k3-whenquery

Conditionally show fields and sections. Better.
MIT License
64 stars 1 forks source link

required field handling #9

Open teichsta opened 2 years ago

teichsta commented 2 years ago

Hi,

thanks for providing this great plugin! I am wondering if there is a way to deal with required fields like in kirby itself. If a required field is hidden a page is considered "valid". While whenQuery doesn't seem to take this into account. Even hidden fields are evaluated while changing the pages state, correct?

Is there a way around it?

Best, Thomas E.-E.

rasteiner commented 2 years ago

In theory this plugin should behave exactly like the when property of standard Kirby, since it overrides the function that when uses (the meetsCondition function). It doesn't actually actively "hide" sections and fields, it just answers the question whether a field should be hidden or not. That's why I find it really strange that it behaves differently from the normal when.

Could you provide an example blueprint?

quentin-f451 commented 2 years ago

Hi, I do have the same problem with required fields when they are hidden. Here is a simplified example:

category:
  type: checkboxes
  options:
    value1: Value 1
    value2: Value 2
firstTitle:
  type: text
  required: true
  whenQuery: category ::any($ = "value1")
secondTitle:
  type: text
  required: true
  whenQuery: category ::any($ = "value2")

If I only select value1 in the category fields, I still have an alert if secondTitle (that is hidden) is empty.

teichsta commented 2 years ago

does this example help @rasteiner ?

rasteiner commented 2 years ago

Yes, sorry. I was swallowed by deadlines. It seems like kirby also checks on the serverside if a field is required or not.

This makes it much more difficult, because the query can currently only be evaluated in the browser. Also, I don't believe I can change the serverside code in any way from a plugin.

So, currently I have no idea how I could fix this.

moritzpflueger commented 6 months ago

I have the same issue using kirby v4.

rasteiner commented 6 months ago

Unfortunately the situation in Kirby 4 has not changed. There is no reasonable way to extend this behaviour in Kirby. Even if I'd implement the query parser in server side code, there is no way I could make Kirby use it.

The only solution would be to integrate this functionality into Kirby core; I already asked the team about this and there doesn't seem to be much interest in accepting such a pull request.