bower install angular-formstamp
<form class="form-horizontal" role="form" name="form" ng-app="form-demo"> <div class="form-group" ng-class="{'has-error': form.username.$invalid}"> <label for="username" class="col-sm-2 control-label">Username</label> <div class="col-sm-10"> <input type="text" class="form-control" id="username" placeholder="Username" required="required" ng-pattern="/awesome/" name="username" ng-model="username" /> <p class="alert alert-danger" ng-show='form.username.$error.pattern'> Username should be awesome </p> </div> </div> <div class="form-group" ng-class="{'has-error': form.email.$invalid}"> <label for="email" class="col-sm-2 control-label">Email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="email" placeholder="Email" required="required" name="email" ng-model="email" /> <p class="alert alert-danger" ng-show='form.email.$error.email'> Email should be valid </p> </div> </div> <div class="form-group" ng-class="{'has-error': form.password.$invalid}"> <label for="password" class="col-sm-2 control-label">Password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="password" placeholder="Password" required="required" name="password" ng-model="password" ng-minlength='6' /> <p class="alert alert-danger" ng-show='form.password.$error.minlength'> Password should be longer </p> </div> </div> <div class="form-group"> <label for="birthDate" class="col-sm-2 control-label">Birth Date</label> <div class="col-sm-10"> <input type="date" class="form-control" id="birthDate" placeholder="Birth Date" ng-model="birthDate" /> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">Sign up</button> </div> </div> </form>
<fs-form-for model="samurai"> <fieldset class="form-horizontal"> <fs-input as="text" name="username" required="" label="Name"></fs-input> <fs-input as="email" name="email" required="" label="Email"></fs-input> <fs-input as="password" name="password" required="" label="Email"></fs-input> <fs-input as="fs-date" name="birthdate" required="" label="Date of Birth"></fs-input> </fieldset> </fs-form-for>
fsFormFor
- a directive that creates a form, the model
attribute indicates the model for which the form is created;fsInput
is a directive describing each element in a form with the following attributes:as
is the type of the form element;name
- the name of the model attribute;label
- the text of the label.as
attribute.fsSelect
directive. The directive supports the attributes freetext
, items
, ng-model
, ng-required
, ng-disabled
. freetext
The attribute (false by default) defines the behavior of the widget. When freetext=false
widget behaves as select, that is, it allows you to select one element from the list of options. When freetext=true
widget behaves like a combo box, that is, it allows you to select a value from the list of options or enter any other. items
The attribute indicates which property of the scop contains a list of options displayed in the widget. With freetext=false
options can be both objects and primitive types. With freetext=true
options can only be strings. ng-model
The attribute is a standard ngModel directive. ng-disabled
The attribute indicates which scop property determines whether the widget is disabled / enabled.$scope.arrayOfOptions
, the selected option is associated with $scope.selectedOption
, and the state of disabled / enabled depends on $scope.flag
, we write the directive as follows: <div fs-select items=”arrayOfOptions” ng-disabled=”flag” ng-model=”selectedOption” freetext=”true”></div>
fsList
- displays a list of items, allows you to select an item in the list and move the selection from the keyboard;fsNullForm
- hides the form element associated with the ngModel from the parent form;fsInput
- simplifies handling of keyboard events and focus changes;fsCalendar
- displays a calendar and allows you to mark the date as selected.fsList
and fsInput
. Working with the fsList
done by interacting with the listInterface
property on the $scope
. listInterface
has the following properties:selectedItem
is the currently selected value. Read only.onSelect(value)
- handler for the value selection event. Must be implemented by the user.move(d)
is a function that moves a pointer to a specified number of elements.audio
tag from html5 in itself: app.directive("demoAudio", function() { return { restrict: "E", scope: { track: '=' }, template: "<audio controls />", replace: true, link: function($scope, $element, $attrs) { return $scope.$watch('track', function(track) { $element.attr('src', track.stream_url + "?client_id=8399f2e0577e0acb4eee4d65d6c6cce6"); return $element.get(0).play(); }); } }; });
<script src="http://connect.soundcloud.com/sdk.js"></script>
function ListDemoCtrl($scope) { // SoundCloud SDK SC.initialize({ client_id: '8399f2e0577e0acb4eee4d65d6c6cce6' }); // SoundCloud $scope.$watch('search', function () { SC.get('/tracks', { q: $scope.search, license: 'cc-by-sa' }, function(tracks) { $scope.$apply(function() { $scope.tracks = tracks }) }) }); $scope.search = 'bach'; $scope.tracks = []; // fsList $scope.move = function (d) { $scope.listInterface.move(d); }; // fsList $scope.listInterface = { onSelect: function (selectedItem) { $scope.select(selectedItem) } }; $scope.select = function(selectedItem) { $scope.selectedTrack = selectedItem || $scope.listInterface.selectedItem; }; }
<div ng-controller="ListDemoCtrl" style="postion: relative;"> <div class="row"> <div class="col-xs-7"> <!-- fsInput --> <input class="form-control" autofocus="1" fs-input fs-up="move(-1)" fs-down="move(1)" fs-enter="select()" ng-model="search"> <!-- fsList --> <div fs-list="" items="tracks" class="no-popup"> <!-- --> <img src="{{ item.artwork_url }}" width="30" height="30"> {{item.title}} <small class="text-muted">{{item.genre}}</small> </div> </div> <div class="col-xs-5"> <!-- fsList - --> <demo-audio track="selectedTrack"></demo-audio> <pre style="margin-top: 20px;">Selected Item: {{ selectedTrack | json }}</pre> </div> </div> </div>
Source: https://habr.com/ru/post/216391/
All Articles