Note that there are some explanatory texts on larger screens.

plurals
  1. POMark fields not valid as red with knockout/durandal
    text
    copied!<p>I am learning knockout, Durandal and Breeze and thanks to the <strong>JumpStart SPA video from John Papa</strong> this is a pleasure. So I examine the code of this project and right now I am trying to change the validation mechanism. </p> <p>At this time, when saving changes, if the save failed, we collect the errors and display a toast with a resume of the errors.</p> <p><img src="https://i.stack.imgur.com/0FXD1.png" alt="enter image description here"></p> <p>What I would like to achieve is:</p> <ul> <li><p>having the ability to mark fields not valid in red (background-color) in the view</p></li> <li><p>when a toast is displayed with the validation errors resume (something like: 'Save failed: affairNr is required' ) I would like to replace the property name with a more friendly name (something like 'Save failed: affair number is required')</p></li> </ul> <p>Here is the portion code for the validation in the datacontext.js:</p> <pre><code>var saveChanges = function () { return manager.saveChanges() .then(saveSucceeded) .fail(saveFailed); function saveSucceeded(saveResult) { log('Saved data successfully', saveResult, true); } function saveFailed(error) { var msg = 'Save failed: ' + getErrorMessages(error); logError(msg, error); error.message = msg; throw error; } }; function getErrorMessages(error) { var msg = error.message; if (msg.match(/validation error/i)) { return getValidationMessages(error); } return msg; } function getValidationMessages(error) { try { //foreach entity with a validation error return error.entitiesWithErrors.map(function (entity) { // get each validation error return entity.entityAspect.getValidationErrors().map(function (valError) { // return the error message from the validation return valError.errorMessage; }).join('; &lt;br/&gt;'); }).join('; &lt;br/&gt;'); } catch (e) { } return 'validation error'; } </code></pre> <p>Does someone can point me in the right direction?</p> <p>Thanks in advance.</p> <hr> <p>EDIT:</p> <p>To reproduce the problem: click on the left sidebar on Transports + recherche avancee + any item in the list + on the right side: clear some inputs (like Numero d'affaire as screenshot below) then click on 'Enregistrer'. Then the save button is called. There I need to check if there are invalid inputs with ko.validation.group but it doesn't work.</p> <p><img src="https://i.stack.imgur.com/zv6m7.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload