Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:35:45+00:00 2026-06-13T02:35:45+00:00

This is the code: var MyModel = Backbone.Model.extend({ defaults: {std:, pod: } }); var

  • 0

This is the code:

var MyModel = Backbone.Model.extend({
    defaults: {std:"",
               pod:""
              }
});

var MyView = Backbone.View.extend({
    tagName:'ul',
    events: {
    'change input' : 'changed',  // When input changes, call changed.
    'hover .std'   : 'timepick', // 
    'mouseout .std': 'doesntwork'
    },
    template:_.template($('#mytemplate').html()),

    initialize: function() {
        this.model.bind('change:pod',this.render,this); // When pod changes, re-render
    },
    timepick: function(e) {
        $('.std').each(function(){
            $.datepicker.setDefaults({dateFormat:'mm-dd'});
            $(this).datetimepicker({timeFormat:'hh:mm',ampm:false});
        });
    },
    doesntwork: function() {
        // Would this.model.set here but mouseout happens when you select date/time values with mouse
    },
    render: function() {
        $(this.el).html(this.template(this.model.toJSON()));
        return this;
    },
    changed: function(e) {
        var value = $(e.currentTarget).val();       // Get Change value
        var cls = $(e.currentTarget).attr('class'); //Get Class of changed input
        var obj = {}; 
        obj[cls] = value;                       // The model variables match class names
        this.model.set(obj);                        // this.model.set({'std':value})
    }
});

I have a datetimepicker in the UI I’m working on, and having difficulties assigning the value that is selected from the datetimepicker to MyModel.

It appears from using console.log output that ‘change input’ is triggered when clicking on the DTP and assigns the default value of (MM-DD 00:00). Even when you select a different date/time value than the default, the ‘change input’ is not triggered again, unless you click on the input box (for a second time), and then the correct value is assigned. Not very user-friendly.

So I had the idea that I would just assign the value on mouseout, which didn’t work since mouseout happens when you start to select date/time values. I also tried blur, and that didn’t work either.

Where am I going wrong?

Edit: Here is a jsfiddle.net link that illustrates my problem http://jsfiddle.net/9gSUe/1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:35:46+00:00Added an answer on June 13, 2026 at 2:35 am

    Looks like you’re getting tripped up by jQuery UI’s CSS. When you bind a datepicker to an <input>, jQuery UI will add a hasDatepicker class to the <input>. Then you do this:

    var cls = $(e.currentTarget).attr('class');
    

    on the <input> and get 'std hasDatepicker' in cls.

    There are too many things that will mess around with class so you’re better off using something else to identify the property you want to change. You could use an id if there is only one std:

    <!-- HTML -->
    <input id="std" class="std" ...>
    
    // JavaScript
    var cls = e.currentTarget.id;
    

    or the name attribute:

    <!-- HTML -->
    <input name="std" class="std" ...>
    
    // JavaScript
    var cls = $(e.currentTarget).attr('name');
    

    or perhaps even a HTML5 data attribute:

    <!-- HTML -->
    <input class="std" data-attr="std" ...>
    
    // JavaScript
    var cls = $(e.currentTarget).data('attr');
    

    I think the name attribute would be the most natural: http://jsfiddle.net/ambiguous/RRKVJ/

    And a couple side issues:

    • Your fiddle was including multiple versions of jQuery and that’s generally a bad idea.
    • You don’t have to build an object for set, you can say just m.set(attr, value) if you’re just setting one attribute.
    • You don’t have to $(this.el) in your views, newer Backbones have this.$el already cached.
    • console.log can handle multiple arguments so you can say console.log('Std: ', attrs.std, ' Pod: ', attrs.pod, ' Poa: ', attrs.poa); instead of console.log('Std: ' + attrs.std + ' Pod: ' + attrs.pod + ' Poa: ' + attrs.poa); if you don’t want + stringify things behind your back.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my front-end code (using fetch ) var MyModel = Backbone.Model.extend(); var MyCollection
I have a code similar to this: My View @model MyCode.Models.RemarksModel foreach (var row
I have a model which looks like this: //myModel.js define([], function () { var
This code var offset = $('#snapwrap_inner').offset(); alert(offset.left) in FF returns 0px but in Opera
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
With this code: var db = google.gears.factory.create('beta.database'); db.open('cominar'); db.execute('CREATE TABLE IF NOT EXISTS Ajax
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
Consider this code: var img = new Image(); img.onload = function() { console.log(this.width); };
I have this code: var query = _cityRepository.GetAll( u => u.PartitionKey == pk &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.