Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= f.text_field :name, required: '', 'ng-model': 'html.name', 'unique-name': '', 'ng-model-options': '{ debounce:500 }' %>
- app.directive('uniqueName', function ($http, $q) {
- return {
- require: 'ngModel',
- link: function(scope, element, attrs, ngModel) {
- ngModel.$asyncValidators.unique = function (name) {
- var id = document.getElementById('id');
- var path = location.pathname;
- return $http.get(path.substr(0, path.indexOf('/', 8) + 1)+'verify?name='+name+'&id='+(id && id.value ? id.value : 0)).then(
- function (response) {
- return response.data.error ? $q.reject() : true;
- }
- );
- };
- }
- };
- });
- def verify
- render json: Admin::Html.select(:name).where(name: params[:name]).where.not(id: params[:id]).empty? ? { success: 'Record not found.' } : { error: 'Record found.' }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement