formkit / docs-content

The content (.md format) — and only the content — for the FormKit documentation site.
17 stars 28 forks source link

Casting value in schema #78

Closed comhon-project closed 7 months ago

comhon-project commented 1 year ago

in chapter schema -> loops, there is a block casting that say we must cast values sometimes. but in the example, it seems to work without performing the cast $key * 1. maybe cast is not required anymore or the example is not relevant

andrew-boyd commented 1 year ago

Thanks for this report — here's the relevant example updated without casting.

https://formkit.link/2451aba9e7bd547ce3ed74c6a67515cf

@justin-schroeder, has something changed regarding the need for casting? https://formkit.com/essentials/schema#loops

justin-schroeder commented 1 year ago

Oh yeah, we patched that issue a few months ago. Good catch.

kswedberg commented 11 months ago

Here is the text of that "Casting" block:

Sometimes schema expressions need to cast a string to a number. For example, keys are always string values during an iteration, so in the above example it was necessary to cast $key to an integer before adding it to 1. To perform this cast, we simply multiplied by 1: $key * 1 before performing our addition.

If casting is no longer necessary, I'd be happy to submit a PR that removes the "Casting" block and updates the example.

@justin-schroeder, just say the word.

justin-schroeder commented 11 months ago

yeah that should have been updated. Would love a fix for that @kswedberg