Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-27982

Web UI - Leverage validation report client side and allow async layout validation

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 11.1, 2021.0
    • Component/s: Web UI
    • Tags:
    • Upgrade notes:
      Hide
      • Layout validate method can now return a Promise in which case it must resolve to true to validate the layout.
      • Server-side schema constraint violations are now reported at the top of the create and edit form layout.
      • Server-side, you can now trigger a global validation error by throwing the following exception:
        throw new DocumentValidationException("your.error.message");
        

        in a synchronous listener on aboutToCreate or beforeDocumentModification. Note that your listener must bubble the exception to prevent the creation or modification. The error message of the exception will be translated Web UI (client) side and reported at the top of the create or edit form.

      Show
      Layout validate method can now return a Promise in which case it must resolve to true to validate the layout. Server-side schema constraint violations are now reported at the top of the create and edit form layout. Server-side, you can now trigger a global validation error by throwing the following exception: throw new DocumentValidationException( "your.error.message" ); in a synchronous listener on aboutToCreate or beforeDocumentModification . Note that your listener must bubble the exception to prevent the creation or modification. The error message of the exception will be translated Web UI (client) side and reported at the top of the create or edit form.
    • Team:
      GANG
    • Sprint:
      nxGang Sprint 11.1.19, nxGang Sprint 11.1.20, nxGang Sprint 11.1.21
    • Story Points:
      5

      Description

      `validate` hook in WebUI is important to give feedback on invalid fields, but we need to add a same hook for asynchronous call (like external call, or operation call).

      why not call it `$validate` or `validateAsync` : 

      // Trigger the layout ASYNC validation if it exists.
      $validate() {
          return this.$.myOp.execute()
              .then((ret) => {
                  if (!ret || !ret.value) {
                       const element = this._getValidatableElement();
                       element.invalid = true;
                       element.errorMessage = "we have a pb here";
                       return Promise.reject('Pre validation service problem.');
                  }
              });
      },
      
      

       

      As example, the new _create we implement in our project now looks like :

      _create() {
          const elementsToValidate = this._getValidatableElements();
          let valid = true; 
          let validations = [];
          elementsToValidate.forEach(el => {
              if (valid && el.validate) {
                  valid = el.validate();
              }
              if (valid && el.$validate) {
                  validations.push(el.$validate());
              }
          });
          if (!valid) {
              return;
          }
      
          Promise.all(validations)
              .then(() => {
                  this.document.name = this.document.name || this._sanitizeName(this.document.properties['dc:title']);
                  this.set('creating', true);
                  return this.$.docRequest.post();
              })
              .then((response) => {
                  this.$.creationStats.storeType(this.selectedDocType.id);
                  this._clear();
                  this.navigateTo('browse', response.path);
                  this._notify(response);
                  this.set('creating', false);
              })
              .catch((err) => {
                  this.set('creating', false);
                  this.fire('notify', {message: this.i18n('documentCreationForm.createError')});
                  console.error(err);
              });
      },
      

       

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 week, 4 hours, 45 minutes
                  1w 4h 45m