formie icon indicating copy to clipboard operation
formie copied to clipboard

getCurrentPageIndex will return null if index is 0

Open bartdigitalpulse opened this issue 3 years ago • 3 comments

Description See https://github.com/verbb/formie/blob/8f1a58c28b3c8166756d61d6d0393af235d68978/src/elements/Form.php#L815:L817

If you are on the first page it will return null because when the $index is 0 it will be seen as false.

bartdigitalpulse avatar Jun 30 '22 14:06 bartdigitalpulse

Is that a problem? The correct behaviour should be that it's null when the index has yet to be set. 0 would be returning if say you submitted the form and it failed validation (returning you to the first page), or if you navigate back to the first page.

Happy to amend, but would like to hear your use-case. And also the Craft/Formie version you're on.

engram-design avatar Jul 01 '22 10:07 engram-design

Yeah it's kinda nitpicky. I'm on Craft Pro 3.7.44 and Formie 1.6.1.

I'm using this for a custom validation where I have 10 fields on the second page where at least one has to be filled in. When I don't add this page check the validation error will already be shown on the first visit, before the submit of the second page. I didn't needed the first page but was confused why it returned null.

bartdigitalpulse avatar Jul 04 '22 07:07 bartdigitalpulse

All good, just wanted to check! I'll have that fixed up, but might be in Formie v2 with some other changes related to pages and active states.

engram-design avatar Jul 04 '22 08:07 engram-design

Fixed for the next release. To get this early, change your verbb/formie requirement in composer.json to:

"require": {
  "verbb/formie": "dev-craft-4 as 2.0.9",
  "...": "..."
}

Then run composer update.

engram-design avatar Sep 04 '22 23:09 engram-design

Fixed in 2.0.10

engram-design avatar Sep 11 '22 05:09 engram-design