Code Monkey home page Code Monkey logo

form-wrapper-js's People

Contributors

johnmarkt avatar nevoss avatar rasliche avatar romanslonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

form-wrapper-js's Issues

How to use $addFields without losing previous rules?

I am trying to edit the items of a project, but when I try to enter the values of my existing project in the form instance I lose the validation rules...

<script>
    import {Form} from 'form-wrapper-js'
    import {required} from '../../../support/form/validation'

    export default {
        name: 'UpdateProjectModal',
        props: ['project'],
        data() {
            return {
                form: Form.create({
                    name: {
                        value: null,
                        rules: [required('É necessário informar um nome')]
                    }
                })
            }
        },
        created() {
            this.form.$addFields(JSON.parse(JSON.stringify(this.project)))
        }
    }
</script>

Also getting this warning: Form-wrapper-js warn]: 'name' is already exists

How can I solve this?

I achieved the desired result with the following:

created() {
    this.form.name = this.project.name
    this.form.description = this.project.description
}

But there are other models with more than 30 fields... And the fields should be dynamic...

Another solution I have found is the following:

data() {
    return {
        form: Form.create({
            name: {
                value: this.project.name,
                rules: [required('É necessário informar um nome')]
            },
            description: {
                value: this.project.description
            }
        }),
        waitingResponse: false
    }
}

Is this right?

[Feature] adding and removing fields

For now, there is no way to add and remove fields from the form, and we are stuck with the fields that were generated in the constructor.

The idea is to add new methods that will help dynamically add and remove fields from the form.

e.g:

const form = new Form()

form.$addField('name', null)
form.$addFields({
  name: null,
  last_name: {
    value: null,
    rules: [required]
  } 
})

form.$removeField('name')
form.$removeFileds(['name', 'last_name'])

Improve the build of the library + some administration stuff

In order to achieve version 1, there is a need to improve the build flow of the library.

  • Change the flow of rollup - first, compile typescript to Js and then build with rollup.
  • Add TS lint or something similar to the CI and to the build flow.
  • Write some description to the library in the head of the main index file.
  • Update all the dev dependencies of the library.
  • Adding Github MD files.

Promise base validation

The idea is to let users return Promise in the validation function ("passes" function).

Then field can be validate throw api end point.

Maybe set some prop that hold the currently validating fields.

[Feature] form collection

Sometimes there is a constraint to create a collection of Forms, you have a group of fields that can be duplicate certain of time.

An example of that is a 'phone' collection, a user can have more than one phone number, one can be mobile and one can be a work phone.

const form = new Form({
  first_name: null,
  last_name: null,
  phones: new FormCollection({
    type: "mobile",
    number: null
  })
});

The new class FormCollection is actually a collection of forms, the object that passes to the constructor of the FormCollection is the same object that passes to the Form class, the only difference is that the object is a prototype, this is mean that the FormCollection holds an array of forms and every time we call the function form.phones.add(), it will add a new Form to the collection of forms, the new Form that will be created will be constructed with the prototype fields

form.phones.add()
forms.all()[0].$fill({
  type: 'mobile',
  number: '0000000'
})

form.phones.add()
forms.all()[1].$fill({
  type: 'work',
  number: '9999999'
})

This code will create two Forms, those 2 forms use the fill function like normal forms, of course, we can make a for loop in our framework template engine and bind events that will fill those forms.

When we call form.$values() the return object will look like this:

{
  first_name: null,
  last_name: null,
  phones: [
    {
      type: 'mobile',
      number: '0000000'
    },
    {
      type: 'work',
      number: '9999999'
    },
  ]
}

This is a nice and clean way to send it to our backend

How to set dynamic rules?

checkMailingContent() {
    if(this.form.mailing_content == 'C'){
        this.form.message.rules = [required('É necessário informar a descrição do mailing')]
    } else{
        this.form.message.rules = []
    }
}

Adding "touched" propery

need to add a "touched" property to the Form class.
the property maybe will be a class that manages all the touched fields, along with an API that helps to add to the touched fields, removing and more

Debounce validation on fieldChanged method

setting up the option to debounce validation in fieldChnaged method.

this is a preparation for the promise base validation related to #28, that's because promise base validation can take time and we don't want to validate every input event.

Adding "onFocus" property

Need to add a new property that saves the field key of the input on focus right now,
and also add some API methods, so the property can be manageable like "setOnFocus" and "unsetOnFocus", and maybe think about other staff, that should help manage the "onFocus" property.

Error sending form with array

I have a small problem when submitting a form that has an array. First I sent the form without being filled, then I filled it out and tried to send it again. The values service_id and currency are filled in correctly, however resending is not allowed due to the array.

This is my form:

form: Form.create({
    service_id: null,
    currency: null,
    costs: [
		{
			value: null,
			starting_track: null,
			final_track: null
		},
		...
	]
})

Screen Shot 2020-08-02 at 15 52 00

These are the errors returned from my API:

{
   "message":"The given data was invalid.",
   "errors":{
      "service_id":[
         "The service id field is required."
      ],
      "currency":[
         "The currency field is required."
      ],
      "costs.0.value":[
         "The costs.0.value field is required."
      ],
      "costs.0.starting_track":[
         "The costs.0.starting_track field is required."
      ],
      "costs.0.final_track":[
         "The costs.0.final_track field is required."
      ]
   }
}

This is the error returned by the package:

Screen Shot 2020-08-02 at 15 57 30

Somehow, he doesn't recognize that the inputs costs.0.final_track, costs.0.starting_track and costs.0.value have been filled.

How can I get around this situation?

Changing the "reset" method on Form class

This is very confusing the reset method on the Form class is just set all the fields data to the original data that was sent into the constructor, this method should reset also the $dirty and the $errors.

need to find another name to the reset method, and create a new method for the "data reset", also maybe change the name of the data and originalData properties to values and initialValues

Logo for the library

Hey,
I am a very bad designer, so if someone can help me create a nice logo for the library it will be great 😄 .

You can use any colors you like if the logo will be fit for the library I will change the colors of the site to the logo colors.

Creating warning

right now the library not throwing or logging in the console any warn error.

  1. need to create a warning function or use an existing one
  2. scan the code to add some warning (etc: "field key doesn't exist.")

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.