Last active
August 29, 2015 14:01
-
-
Save colinmacdonald/f322b1c06e2194f99634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://cdn.goinstant.net/v1/platform.min.js"></script> | |
<script src="bower_components/angular/angular.js"></script> | |
<script src="bower_components/goangular/dist/goangular.js"></script> | |
<script src="js/query.js"></script> | |
</head> | |
<body> | |
<h2>Angular JS Test</h2> | |
<form ng-submit="save()" ng-app="skyforms" ng-controller="personCtrl"> | |
<label>Find User:</label> | |
<input type="text" ng-model="search" placeholder="Enter First Name to Search..." /> | |
<input type="button" id="Find" value="Search" ng-click="Find()" /> | |
<hr /> | |
<div> | |
<label>Full User Name:</label> | |
<div> | |
<input type="text" ng-model="person.userName" /> | |
<label>First Name:</label> | |
<input type="text" ng-model="person.firstName" /> | |
<label>Last Name:</label> | |
<input type="text" ng-model="person.lastName" /> | |
</div> | |
<button ng-show="person.id" type="submit" id="save" name="save" ng-click="Save(person.id)">Save</button> | |
<input type="button" id="Create" value="Insert Person" ng-click="Create()" /> | |
</div> | |
</form> | |
<body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('skyforms', ['goangular']) | |
.config(['$goConnectionProvider', function ($goConnectionProvider) { | |
$goConnectionProvider.$set('https://goinstant.net/ACCOUNT/APP'); | |
}]) | |
.controller('personCtrl', function ($scope, $goQuery, $goKey) { | |
$scope.people = $goKey('person', {}, {}); | |
$scope.search = null; | |
$scope.Find = function() { | |
$scope.person = $goQuery('person', { userName: $scope.search }, { limit: 1 }).$sync(); | |
$scope.person.$on('ready', function() { | |
var id = $scope.person.$$index[0]; | |
if (!id) { | |
// no results found | |
return; | |
} | |
$scope.person = $scope.person[id]; | |
$scope.person.id = id; | |
}); | |
}; | |
$scope.Save = function(id) { | |
$scope.people.$key(id).$set({ | |
userName: $scope.person.userName, | |
firstName: $scope.person.firstName, | |
lastName: $scope.person.lastName | |
}); | |
}; | |
$scope.Create = function() { | |
$scope.people.$add({ | |
userName: $scope.person.userName, | |
firstName: $scope.person.firstName, | |
lastName: $scope.person.lastName | |
}); | |
}; | |
}); |
What would be the best way to reset the form to make way for adding a new record?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Colin! This works excellent!