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

Introspection to create input field validation in HTML DSL #99

Open
anderssv opened this issue May 4, 2024 · 1 comment
Open

Introspection to create input field validation in HTML DSL #99

anderssv opened this issue May 4, 2024 · 1 comment

Comments

@anderssv
Copy link

anderssv commented May 4, 2024

I suspect it is not possible, but I have to check: I want to use Konform with HTML DSL and generate HTML form validation information (required, minlength etc). But to do that I would need some kind of introspection of which validations is applied to an Validation/Object.

Is it possible? It would make it really useful in combination with other things. 😃

Found this so suspect it's not possible, but honestly not that intimate with deep Kotlin details: #27

@dhoepelman
Copy link
Collaborator

dhoepelman commented May 10, 2024

Hey @anderssv ,

this isn't really possible for the reasons outlined in the issue you linked. Konform has the validation logic as code, not in a way that could be used the generate minlenght="..." etc. Changing this to something that is declarative and could be used to generate HTML forms, JSON schema et.c is way out of scope.

You could do something like this yourself and convert it into both konform and html form validation:

data class HtmlFormAndKonformValidation(
   val minlength: Int? = null
   // ..
) {
  private val me get() = this

  fun toHtmlFormValidation() = // ...

  val konform = Validation<String> {
    if(me.minlength != null) minlength(me.minlength)
  }
}

data class MyThing(val foo: String)
val myThingFooValidation = HtmlFormAndKonformValidation(minlenght = 5)

val myThingKonformValidation = Validation<MyThing> {
  MyThing::foo { run(myThingFooValidation.konform) }
}

@dhoepelman dhoepelman closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@dhoepelman dhoepelman reopened this Dec 25, 2024
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