How can jQuery() pick up the change date

46 views
Skip to first unread message

Rudy

unread,
Apr 25, 2017, 6:01:12 AM4/25/17
to web2py-users
Hi there,

I tried to generate a CREATE FORM using below, then in my view, I added a script trying to change the renew_date when an user changes the start_date by using .change(function()). jQuery could detect the change if I manually modified the date in the textbook, but not when I chose a date from the calendar. I read online seeing others suggesting to use .on('changeDate', function()), but it's still not working, any pointer is much appreciated.

I am very new to javascript, i read online about jQuery, but it seems what people suggest don't work in web2py environment eg. on('changeDate'), .datepicker(). Could anyone point me to any useful documentation / tutorials about "using jQuery in web2py"? I have read chapter 11 of web2py online book, can't find anything about changeDate, should we use changeDate? if so, where can I find the complete list of events and effects?


db.define_table('subscription',
                Field('item', 'reference item',  writable=False, label='Item Id'),
                Field('start_date', 'date', default=request.now),
                Field('renew_date', 'date', default=request.now+six_month),
                Field('service_details', 'text'))

form = SQLFORM(db.subscription).process()

<script>
jQuery(document).ready(function(){
    alert("hello hello");
    $('.datepicker').datepicker({
        format: "yyyy-mm-dd",
    }) 
    
    jQuery('#subscription_start_date').change(function(){
        alert("heeheehee")
        jQuery('#subscription_service_details__row').slideToggle();
    });
    jQuery('#subscription_start_date').on('changeDate', function(){
        alert("xxyyyzzzz")
        jQuery('#subscription_service_details__row').slideToggle();
    });
});
</script>

Anthony

unread,
Apr 25, 2017, 10:12:11 AM4/25/17
to web2py-users
Does it get triggered when the field loses focus? How about if you use .on("input", ...) instead of .on("change", ...)?

Anthony

Rudy

unread,
Apr 25, 2017, 12:26:50 PM4/25/17
to web2py-users
Hi Anthony,

Thanks for your suggestion, below script alert("heeheehee") only got triggered when i moved the cursor in the textbox, edited the date yyyy-mm-dd manually, then moved the cursor to another field. 

after I modified to .on("input"), alert("xxyyyzzzz") only got triggered when I again moved the cursor in the textbox, edited the date yyyy-mm-dd manually, but this time no need to wait till the cursor moved to another field. After alert("xxyyyzzzz"), alert("heeheehee") was triggered immediately with .change()

I wonder if i can use .on('changeDate') and like below


Anthony

unread,
Apr 25, 2017, 3:08:36 PM4/25/17
to web2py-users
On Tuesday, April 25, 2017 at 12:26:50 PM UTC-4, Rudy wrote:
Hi Anthony,

Thanks for your suggestion, below script alert("heeheehee") only got triggered when i moved the cursor in the textbox, edited the date yyyy-mm-dd manually, then moved the cursor to another field. 

after I modified to .on("input"), alert("xxyyyzzzz") only got triggered when I again moved the cursor in the textbox, edited the date yyyy-mm-dd manually, but this time no need to wait till the cursor moved to another field. After alert("xxyyyzzzz"), alert("heeheehee") was triggered immediately with .change()

I wonder if i can use .on('changeDate') and like below



From the docs, it looks like .on('changeDate') should work. If it's not, you should probably ask elsewhere, as this is a Bootstrap issue, not web2py.

Anthony
Reply all
Reply to author
Forward
0 new messages