'trim' of undefined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gundogduyakici
    Senior Member
    • Mar 2018
    • 165

    'trim' of undefined

    I click create button then
    Uncaught TypeError: Cannot read property 'trim' of undefined error ?

    Detail:
    Code:
    fetch: function () {
                var data = {};
                var value = this.$element.val();
                if (this.params.trim || this.forceTrim) {
                    [COLOR=#FF0000][U]if (typeof value.trim === 'function') {[/U][/COLOR]
                        value = value.trim();
                    }
                }
                data[this.name] = value;
                return data;
            },
  • dabasystem
    Member
    • Jul 2018
    • 51

    #2
    Hello,
    It also happens to me, I've fixed it by adding this:


    Code:
              
                var data = {};
                var value = this.$element.val();
    [COLOR=#008000][B]            if (value == null) {
                    value = $("input[data-name='"+this.name+"']").val()
                }[/B][/COLOR]
    
                if (this.params.trim || this.forceTrim) {
                    if (typeof value.trim === 'function') {
                        value = value.trim();
                    }
                }
    
                data[this.name] = value || null;
                return data;

    Comment

    Working...