Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

[Documentation Request] Custom Fields and Validators #300

Open
samo9789 opened this issue Feb 9, 2022 · 2 comments
Open

[Documentation Request] Custom Fields and Validators #300

samo9789 opened this issue Feb 9, 2022 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@samo9789
Copy link

samo9789 commented Feb 9, 2022

Hi,

We were able to use a custom field to have a Google Maps auto completed address field.
This field should be mandatory...

Currently, we have

In the form declaration :

address: CustomField({
                        label: 'Adresse',
                        placeholder: '85 rue ...',
                        validations: [
                            Validator({
                                validator: required,
                                text: 'Le champ adresse est obligatoire',
                            }),
                        ],
                    }),

and in the template

<dynamic-form :form="form" @submitted="sendAddress">
            <template v-slot:address="{ control, onChange, onFocus, onBlur }">
                <GMapAutocomplete v-if="control"
                    :placeholder="control.placeholder"
                    @place_changed="setPlace"
                    @change="onChange"
                    @focus="onFocus"
                    @blur="onBlur"
                />
            </template>
        </dynamic-form>

Leaving the field empty does not raise an error while leaving this field empty does show the specified message

name: TextField({
                        label: 'Nom de votre adresse',
                        placeholder: 'Exemple: Maison Paris, Maison de la plage, ...',
                        validations: [
                            Validator({
                                validator: required,
                                text: 'Cette information est  obligatoire',
                            }),
                        ],
                    }),

Could you please add to the documentation how to make use of the validators for custom fields ?

Thank you very much

@alvarosabu
Copy link
Collaborator

Hey, thanks for the request, make totally sense I think is necessary.

@alvarosabu alvarosabu self-assigned this Feb 9, 2022
@alvarosabu alvarosabu added the documentation Improvements or additions to documentation label Feb 9, 2022
@rferreira98
Copy link

rferreira98 commented Jul 20, 2022

@alvarosabu I'm having this issue. Custom field validation doesn't look very stable (I'm doing a checkbox custom field, code's below)


<div class="terms-conditions-field">
              <CheckboxComponent :id="control.name" :value="(control.value === 'on')" @change="onChange"
              @focus="onFocus" @blur="onBlur">
              <template #label>
                Accept
                <a href="#">Terms & Conditions</a>
              </template>
            </CheckboxComponent>
          </div>
          <div class="form-errors">
            <div class="form-error" v-for="err in control.errors">{{ err.text }}</div>
          </div>
  </div>
  

CheckboxComponent events are the input[type=checkbox] events emitted from inside the component.

CodeSandbox here: https://codesandbox.io/s/customfieldissue-vuedynamicforms-81f7ch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants