-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model could not accept null value. It will throw up error. #122
Comments
This is my test form: <form data-query="submit($parent.save)">
<div class="field">
<label>Name</label>
<input type="text" data-query="val(name)"/>
</div>
<div class="field">
<label>Address</label>
<input type="text" data-query="val(address)"/>
</div>
<div class="field">
<label>City</label>
<input type="text" data-query="val(city)"/>
</div>
<div class="field">
<label>State</label>
<input type="text" data-query="val(state)"/>
</div>
<div class="field">
<label>Country</label>
<input type="text" data-query="val(country)"/>
</div>
<div class="field">
<label>Website</label>
<input type="text" data-query="val(website)"/>
</div>
<div class="field">
<label>Timezone</label>
<input type="text" data-query="val(time_zone)"/>
</div>
<div class="field">
<label>Company Code</label>
<input type="text" data-query="val(code)"/>
</div>
<div class="field">
<label>Postal Code</label>
<input type="text" data-query="val(postal_code)"/>
</div>
<div class="field">
<label>Activated</label>
<input type="text" data-query="val(activated)"/>
</div>
<div class="field">
<label>Number of Employee</label>
<input type="text" data-query="val(number_of_employees)"/>
</div>
<div class="field">
<label>Other account</label>
<input type="text" data-query="val(parent_company_id)"/>
</div>
<div class="field">
<label>Sales</label>
<input type="text" data-query="val(sales_rep_id)"/>
</div>
<div class="field">
<label>Customer Success</label>
<input type="text" data-query="val(customer_success_rep_id)"/>
</div>
<div class="field">
<button type="submit" class="btn">Save</button>
</div>
</form> I got this error in the attachment. Thanks for helping. |
Thank you. Also the form should work fine. These errors doesn't stop the execution. |
Ok. Thanks. |
Aha. I got it. Yeah I agree with you @Kanaye. |
Yep, for some of the new adopter like me, we will see that as something wrong. Maybe the message return also could improve a bit. |
Hey @chardy. How could we improve the message(s) from your point of view. Btw. which browsers console is shown in your screenshot above? |
Hi @Kanaye , That browser screenshots is from Chrome. To counter that, I am actually wrote a function to set any response data JSON key which the value is null to be deleted before I pass in to .reset() of a Model. Then solve this issue. function removeNullsInObject(obj) {
if( typeof obj === 'string' ){ return; }
$.each(obj, function(key, value){
if (value === "" || value === null){
delete obj[key];
} else if ($.isArray(value)) {
if( value.length === 0 ){ delete obj[key]; return; }
$.each(value, function (k,v) {
removeNullsInObject(v);
});
} else if (typeof value === 'object') {
if( Object.keys(value).length === 0 ){
delete obj[key]; return;
}
removeNullsInObject(value);
}
});
} success: function(data) {
if(data){
removeNullsInObject(data);
_this.account.reset(data);
} else {
console.log("data error!");
}
} something like that... for now... 👍 |
Hi,
I got this API return:
My model:
I got error of Argument mismatch for the value that contain null.
The text was updated successfully, but these errors were encountered: