Code Monkey home page Code Monkey logo

ionic-input-clearable's People

Contributors

monavari-lebrecht avatar mopi1402 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ionic-input-clearable's Issues

prevent the blur when clicking on the clear button

Feel free to add this one to your directive in order to prevent the input to blur when the user click on the clear button :

$scope.clearInputField = function ( event ) {
$scope.ngModel = '';

                function preventBluring() {
                    element.focus();
                    $element.unbind( 'blur', preventBluring );
                }

                //keep focus on the field when click on the clear button
                $element.bind( 'blur' , preventBluring );
            };

Sometime, call $digest will throw an error.

This is the patch in order to prevent the error throw when $digest is called whereas it's already in progress :

function refresh() {
$timeout( function () {
$scope.$digest();
});

}

$element.bind( 'focus', refresh );
$element.bind( 'blur', refresh );

Sorry about that, it was from my code :p

ngModel changed programmatically

Does the clearable "x" appear if the value of the input is changed dynamically (programmatically) from empty to some other value?

Tags/Releases and bower integration

Looks very nice. For better usage in bower and stuff, it would be nice, if you could provide tags as releases and maybe additonally provide releases in bower library.

minify JS error

When i use visual studio 2013 for Web Essentials,bundle "sw2.ionic.input-clearable.js" get an error,
so i change line 7 and 13 to fix it.Dose anybody occurred same problem?

Provider

And what about a default config ? :)

In my app, I prefer that the button appears only when the field is focused, but, in some field, I want to see the clear button even if the text field is not focused.

So I suggest something like that :

angular.module('sw2.ionic.input-clearable', [])

    .provider('ionicInputClearableConfig', function() {

        this.defaultDisplayType = "filled";

        this.$get = function () {
            return this;
        };
    })

    /**
     * ionicInputClearable might have 3 values :
     - always (the button is always visible even if it's empty)
     - focused (the button appear when the field is focused and filled)
     - [default] filled (the button appear when the field is filled)
     */
    .directive('ionicInputClearable', function ($compile) {
        return {
            restrict: 'A',
            scope: {
                ngModel: '='
            },
            controller: function ($scope, $element, $attrs, ionicInputClearableConfig) {

                var displayType = ($attrs.ionicInputClearable.length > 0 ? $attrs.ionicInputClearable : ionicInputClearableConfig.defaultDisplayType);

                var element = $element[0];

                //Parent element should be position:relative to make clear button in correct positon
                $element.parent().css( "position", "relative" );

                //ng-hide class used to fix init flash problem
                $scope.clearBtn = angular.element('<a tabindex="-1" ng-cloak class="ng-hide input-clear-btn button button-icon icon ion-close" ng-click="clearInputField()" ng-hide="isInputFieldEmpty()"></a>');
                $compile($scope.clearBtn)($scope);
                $element.after($scope.clearBtn);

                $scope.clearInputField = function () {
                    $scope.ngModel = '';
                }

                $element.bind( 'focus', function() {
                    $scope.$digest();
                });

                $element.bind( 'blur', function() {
                    $scope.$digest();
                });

                $scope.isInputFieldEmpty = function () {

                    switch ( displayType ) {
                        case "always"   :
                            return false;
                        case "focused"  :
                            return (document.activeElement !== element || element.value == '' || element.value == null );
                        default :
                            return (element.value == '' || element.value == null);
                    }
                }
            }
        }
    })

Usage :
//Give the ability to choose the default strategy to display the button
var app = angular.module( 'myApp' , ['ionic', 'sw2.ionic.input-clearable'] );
app.config(function(ionicInputClearableConfigProvider) {
ionicInputClearableConfigProvider.defaultDisplayType = "focused";
});

will display only when focused (default configured behavior)
<input ionic-input-clearable ng-model="form.searchText" type="search">
button is always displayed
<input ionic-input-clearable="always" ng-model="form.searchText" type="search">
button is display when the textfield is filled
<input ionic-input-clearable="filled" ng-model="form.searchText" type="search">
button is display when the textfield is focused
<input ionic-input-clearable="focused" ng-model="form.searchText" type="search">

email validation

The button is not showing until the email is correct :

<input ionic-input-clearable name="email" ng-model="form.email" type="email" placeholder="email" required>

fix :
$scope.isInputFieldEmpty = function () { return ($element[0].value == '' || $element[0].value == null ); //return ($scope.ngModel == '' || $scope.ngModel == null ); }

[feature] show button only during editing

The cross will be available only when the input has the focus (like in ios) :

   var element = $element[0];

   $element.bind( 'focus', function() {
         $scope.$digest();
   });

   $element.bind( 'blur', function() {
         $scope.$digest();
   });

   $scope.isInputFieldEmpty = function () {
      return (document.activeElement !== element || element.value == '' || element.value == null );
   }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.