EasyUI Forum
October 04, 2025, 12:54:09 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: dynamically changing datetimebox to datebox?  (Read 15002 times)
tomhj
Newbie
*
Posts: 40


View Profile
« on: June 03, 2013, 04:18:01 PM »

I need to be able to change a datetimebox field to a datebox (to remove the time component for an 'all-day' event) and vice versa.

I tried the technique in this thread http://www.jeasyui.com/forum/index.php?topic=1761.0 but couldn't get it to work:

            $.extend($.fn.datetimebox.methods, {
                    removeTime: function(jq){
                        return jq.each(function() {
                            var state = $.data(this,'datetimebox');
                            if (state) {
                                state.spinner.panel('destroy');
                                state.datetimebox.remove();
                                $(this).removeClass('easyui-datetimebox').show();
                                $.removeData(this,'datetimebox');
                            }
                            $(this).addClass('easyui-datebox').show();
                            if (state)
                                $.setData(this, 'datebox', state);
                        });
                    },
                    addTime: function(jq){
                        return jq.each(function() {
                            var state = $.data(this,'datebox');
                            if (state) {
                                state.spinner.panel('destroy');
                                state.calendar.remove();
                                $(this).removeClass('easyui-datebox').show();
                                $.removeData(this,'datebox');
                            }
                            $(this).addClass('easyui-datetimebox').show();
                            if (state)
                                $.setData(this, 'datetimebox', state);
                        });
                    }
            });

What am I doing wrong?  Or is there a better way to do this?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: June 03, 2013, 07:37:13 PM »

If you only want to hide the timespinner component, extend a method to achieve it. But if you want to change the whole datetimebox to datebox, the more better way is to destroy the old one and then recreate a new datebox component.
Logged
tomhj
Newbie
*
Posts: 40


View Profile
« Reply #2 on: June 03, 2013, 10:37:18 PM »

I need the time component to go away in the text field as well as in the drop down calendar.  Would hiding the timespinner do both?

As far as destroying the old one and then recreating it, that's what I was trying to do with the removeTime and addTime extension methods.  I tried simply using destroy() but that removed the date box/edit field entirely as was noted in that other thread - so I was trying to adapt that other thread's solution to this usage but got bogged down in differences between combo's and date/timeboxes. 

How do you recommend I destroy the old one and re-add the new one in it's place?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: June 04, 2013, 12:12:29 AM »

Try the code below, calling 'todatebox' function will destroy the old datetimebox and then create a new datebox.
Code:
<input id="dt" class="easyui-datetimebox" value="10/11/2012 2:3:56 " style="width:200px">
<script>
function todatebox(){
var oldd = $('#dt');
var value = oldd.datetimebox('getValue');
var newd = $('<input id="dt">').insertBefore(oldd);
oldd.datetimebox('destroy');
newd.datebox({
value: value.split(' ')[0]
});
}
</script>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!