Code Monkey home page Code Monkey logo

Comments (6)

meherfattouch avatar meherfattouch commented on July 18, 2024 1

Hi,
Did you have a solution to trigger vaidation on submit and show errors in each input separatly ? not on a single div ? like :
46904944-a7f11b00-ceec-11e8-99ba-7e19d5e0c90d

from ajsf.

hamzahamidi avatar hamzahamidi commented on July 18, 2024

You can try the following as used in the Demo:

TYPESCRIPT

import { JsonPointer } from 'angular6-json-schema-form';
formValidationErrors: any;

private _prettyValidationErrors (formValidationErrors: any[]): string {
  if (!formValidationErrors) { return null; }
  return formValidationErrors.reduce((a, c) => {
      const arrMessage = JsonPointer.parse(c.dataPath).reduce((aa, cc) => {
          const dd = /^\d+$/.test(cc) ? `[${cc}]` : `.${cc}`;
          return aa + dd;
      }, '');
      return `${a} ${arrMessage} ${c.message} <br>`;
  }, '');
};

validationErrors(data: any): void {
    this.formValidationErrors = data;
 }

get prettyValidationErrors() {
    return this._prettyValidationErrors(this.formValidationErrors);
 }

HTML

 <json-schema-form loadExternalAssets="true" [options]="jsonFormOptions" [schema]="schema" [framework]="selectedFramework" (validationErrors)="validationErrors($event)" >
  </json-schema-form>
 <div *ngIf="!!prettyValidationErrors" class="data-bad" [innerHTML]="prettyValidationErrors"></div>

CSS

.data-bad { background-color: #fcc; }

from ajsf.

hamzahamidi avatar hamzahamidi commented on July 18, 2024

The library already support french language See Here.
Did you try adding language="fr" like this <json-schema-form language="fr"></json-schema-form> ?

from ajsf.

meherfattouch avatar meherfattouch commented on July 18, 2024

Thank you, i update my question, i want to trigger validation to each field, your code put all errors in the div ;

but i want to show errors separately

github

from ajsf.

hamzahamidi avatar hamzahamidi commented on July 18, 2024

The library support both options. As I already told you, Did you try adding language="fr" like this <json-schema-form language="fr"></json-schema-form> ?

from ajsf.

meherfattouch avatar meherfattouch commented on July 18, 2024

Its ok for the language, bu it shows errors in a same div like that :

github11

and i want them to be shown to each field separately:

github

from ajsf.

Related Issues (20)

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.