Skip to content

Instantly share code, notes, and snippets.

@alundiak
Last active Dec 17, 2015
Embed
What would you like to do?
(function (){
var node = document.getElementById('myForm');
function AppViewModel() {
this.uiTypes = ko.observableArray([
{"typeValue":"A", "typeLabel": "1 field type"},
{"typeValue":"B", "typeLabel": "2 fields type"}
]);
this.selectedType = ko.observable();
this.showField1 = ko.observable(false);
this.showField2 = ko.observable(false);
this.valueField1 = ko.observable('');
this.valueField2= ko.observable('');
this.selectedType.subscribe(function (type) {
if (!type){
this.showField1(false);
this.showField2(false);
} else {
this.showField1(true);
this.showField2(type === 'B');
}
this.valueField1('');
this.valueField2('');
}, this);
this.enableExecutionButton = ko.computed(function(){
var a = this.showField1();
var b = this.showField2();
var x = this.valueField1();
var y = this.valueField2();
function AndAndXnor(a,b,x,y) {
//return (a&&b && x&&y || a&&!b && x&&!y); // WORKS
return (a&&x) && (b&&y || !b&&!y); // WORKS
//return (a&&x) && !(b^y); // "(b&&y || !b&&!y)" // DOES NOT WORK
}
return AndAndXnor(a,b,x,y);
}, this);
this.pseudoSubmitForm = function(formElement){
this.selectedType('');
}
}
var model = new AppViewModel();
ko.applyBindings(model, node);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment