Skip to content

Commit

Permalink
Views that are of type 'create' (such as VIEW_WEB_CREATE) will defaul…
Browse files Browse the repository at this point in the history
…t to having hideInitValidationError === true
  • Loading branch information
uzquiano committed Feb 4, 2013
1 parent 3d59eb9 commit 1d92ea3
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 12 deletions.
69 changes: 69 additions & 0 deletions examples/components/validation/validation-examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,75 @@ <h4>DEBUG loggings of ignored fields outside schema</h4>
</script>


<h3>Example 11: </h3>
<h4>Invalid field with VIEW_WEB_CREATE (no init validation)</h4>

<div id="field11">
</div>
<script type="text/javascript" id="field11-script">
$(function() {
$("#field11").alpaca({
"data": "",
"schema": {
"title": "Required field",
"type": "string",
"required": true
},
"view": "VIEW_WEB_CREATE"
});
});
</script>



<h3>Example 12: </h3>
<h4>Custom validator (with VIEW_WEB_CREATE).</h4>
<div id="field12">
</div>
<script type="text/javascript" id="field12-script">
$(function() {
$("#field12").alpaca({
"data": {
"weight" : 100,
"age" : 10
},
"schema": {
"title": "Ride Requirement",
"type": "object",
"properties": {
"weight" : {
"type" : "integer",
"title" : "Weight",
"decription" : "Enter your weight."
},
"age" : {
"type" : "integer",
"title" : "Age",
"decription" : "Enter your age."
}
}
},
"options": {
"validator" : function(control, callback) {
var controlVal = control.getValue();
if (controlVal['weight'] <= 120 || controlVal['age'] <= 12) {
callback({
"message": "Weight must be over 120 and age must be over 12.",
"status": false
});
} else {
callback({
"message": "Valid value (custom validator)",
"status": true
});
}
}
},
"view": "VIEW_WEB_CREATE"
});
});
</script>

</div>
<div class="clear height-fix"></div>
</div>
Expand Down
39 changes: 27 additions & 12 deletions js/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
// finished initializing
this.initializing = false;

this.hideInitValidationError = Alpaca.isValEmpty(this.options.hideInitValidationError) ? false : this.options.hideInitValidationError;
var defaultHideInitValidationError = (this.view.type == 'create');
this.hideInitValidationError = Alpaca.isValEmpty(this.options.hideInitValidationError) ? defaultHideInitValidationError : this.options.hideInitValidationError;

// final call to update validation state
if (this.view.type != 'view') {
Expand Down Expand Up @@ -697,10 +698,17 @@
// Push the message
this.validation[valId] = valInfo;

if (valInfo && !valInfo.status) {
this.getEl().removeClass("alpaca-field-valid");
this.getStyleInjection("error",this.getEl());
this.getEl().addClass("alpaca-field-invalid");
if (!this.hideInitValidationError) {

// we don't markup invalidation state for readonly fields
if (!this.options.readonly)
{
if (valInfo && !valInfo.status) {
this.getEl().removeClass("alpaca-field-valid");
this.getStyleInjection("error",this.getEl());
this.getEl().addClass("alpaca-field-invalid");
}
}
}

// Push the message
Expand All @@ -709,22 +717,29 @@
// Allow for the message to change
if (this.options.showMessages) {
if (!this.initializing) {
var messages = [];
for (var messageId in this.validation) {
if (!this.validation[messageId]["status"]) {
messages.push(this.validation[messageId]["message"]);

if (!this.hideInitValidationError) {

// we don't markup invalidation state for readonly fields
if (!this.options.readonly)
{
var messages = [];
for (var messageId in this.validation) {
if (!this.validation[messageId]["status"]) {
messages.push(this.validation[messageId]["message"]);
}
}
this.displayMessage(messages, beforeStatus);
}
}
this.displayMessage(messages, beforeStatus);
}
}
// Revalidate parents if validation state changed

// Revalidate parents if validation state changed
if (this.isValid() && this.parent && this.parent.renderValidationState) {
this.parent.renderValidationState();
}


}
},

Expand Down

0 comments on commit 1d92ea3

Please sign in to comment.