I have a form which has a postal code field. The field should be able to accept postal code in these formats: “M5N 3N4”, “M5N3N4”. I have a computed property that strips out the space in middle. How can I post the value of the computed to the web API and exclude the non-formatted model attribute for postal code?
It’s dirty and I’m sure there is a much better way to accomplish this but…
export default Ember.Component.extend({
layout: layout,
onChange: function(value) {
// This was just a test. This does not format to your requirements.
var myval = $("input[name='postalcode']").val().replace(/\s+/g, '-').replace(/([^a-zA-Z0-9\-])/g, "").toLowerCase();
Ember.run.later((function() {
Ember.$("input[name='postalcode']").val(myval);
}), 0)
}.observes('myModel.postalcode')
});