Giter VIP home page Giter VIP logo

Comments (3)

LinusMuema avatar LinusMuema commented on August 29, 2024

Hi @OtienoSamwel

About the validators:

  1. for phone and email, since we're providing our own regex, you can localise the regex in the respective functions to reduce the number of parameters passed.
  2. You can change from sealed class to sealed interface since we're only implementing methods. Also this can help too.
  3. The min and max validators don't check character length but the actual integer value. So you can change the error messages accordingly.
  4. You can hoist the error messages to be constants in the same file.

from form-builder.

LinusMuema avatar LinusMuema commented on August 29, 2024

Also, I wanted us to change the format of TextFieldState.

I wanted the state to provide the composable too via a composable function ergo, we will rename the state to FormField and pass in the validators and any other attributes from #2

So the end result will be.

@Composable
fun MyForm(){
    val formState by remember { FormBuilderState() }
    
    FormBuilder(
        state = state,
        fields = [
            FormField(
                name = "email",
                validators = [Required, Email]
            ),
            FormField(
                name = "age",
                validators = [Required, Min(18)]
            )
        ]
    )
    
    // to validate
    if (state.validate()){
        val data = state.values() // {[email protected], age=13}
    }
}

// in the field state
class FormField(validators: List<Validator>){
   @Composable
   internal fun content(){
      // the material text field
   }
}

// in the form state during render
fields.forEach { state ->
   state.content()
}

from form-builder.

LinusMuema avatar LinusMuema commented on August 29, 2024

resolved

from form-builder.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.