Skip to content

Instantly share code, notes, and snippets.

@gabouh
Created March 28, 2016 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabouh/18112b3326cd0e02a8ab to your computer and use it in GitHub Desktop.
Save gabouh/18112b3326cd0e02a8ab to your computer and use it in GitHub Desktop.
SearchBar implementation - Not working
Model.set("searchVisible", false);
Model.searchShow = function() {
this.set("searchVisible", true);
};
Model.searchHide = function() {
this.set("searchVisible", false);
};
// I'm using a definedProperty for a specific reason -- if you don't need a event you can attach to fired per character inserted into the search bar
// Then just doing a Model.set("searchValue", ""); is all you need rather than the code below.
Object.defineProperty(Model, "searchValue", {
get: function () {
return this._searchValue;
},
set: function (v) {
if (this._searchValue !== v) {
this._searchValue = v;
this.notify({ object: this, eventName: "searchValue_changed", propertyName: "searchValue", value: v });
}
},
enumerable: true,
configurable: true
});
var Model = require("../../shared/view-models/home-view-model");
var bindingContext = new Observable.Observable({
title: 'Home',
myItems: new ObservableArray.ObservableArray([])
});
exports.loaded = function(args) {
var page = args.object;
page.bindingContext = { bindingContext:bindingContext };
};
exports.searchHide = function() {
Model.searchHide();
};
exports.searchSubmit = function() {
Model.searchHide();
console.error("Search Value:", Model.searchValue);
};
<page loaded="loaded" xmlns:drawer="nativescript-telerik-ui/sidedrawer" xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:gv="nativescript-grid-view">
<SearchBar textFieldHintColor="#ffffff" hint="Search..." text="{{ searchValue }}" col="1" colSpan="2" visibility="{{ searchVisible ? 'visible' : 'collapsed' }}" submit="searchSubmit" clear="searchHide" cssClass="mainSearch"/>
</page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment