0

I'm having a problem with changing an input's value. The code below works but it's only setting the html value="geolocationvaluehere", the problem is that it doesn't display the text in the input (geolocationvaluehere), it's empty.

I've tried using self.ui.location.val(loc.city) too but with no success.

View.Form = MyProject.CustomItemView.extend({
  template: formTpl,

  ui: {
    location: 'input[name=location]'
  },

  onRender: function () {
    var self = this;

    this.saveLocationToStorage(function(err) {
      if( ! err && localStorage.getItem('geoLocation')) {
        var loc = JSON.parse(localStorage.getItem('geoLocation'));

        if(self.ui.location[0]) self.ui.location.attr('value', loc.city);
      }
    });
  }
});
Kristjan Kirpu
  • 674
  • 1
  • 7
  • 26
  • What is `self.ui` ..? a `
    `..? not sue how you expect `self.ui.location` to point to an `input`
    – T J Oct 28 '15 at 10:13
  • What type of input is `self.ui.location`? – joews Oct 28 '15 at 12:57
  • @KristjanKirpu in that case `self.ui.location.val` should work fine - see the JSBin in my answer. Does that JSBin work in your browser? – joews Oct 28 '15 at 15:09

1 Answers1

0

You should set the value with the jQuery val function rather than attr:

self.ui.location.val(loc.city);

JSBin

joews
  • 29,767
  • 10
  • 79
  • 91