Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value #5

Open
seleckis opened this issue Jan 11, 2015 · 8 comments
Open

Default value #5

seleckis opened this issue Jan 11, 2015 · 8 comments

Comments

@seleckis
Copy link

Hi! Love this plugin.
I have a question: how to set default value (start_time) using html, not js. Now it works like this:

$(".js-timepicker").timepicki({
    start_time: ["20", "00"]
});

but it is not convenient. Why not just take default value from value attribute?

<input type="text" value="20:00" class="js-timepicker">

Moreover, divider is now " : ", but I want to use ":", without spaces, but there is no option to change this.
Thanks in advance.

@diegoburgio
Copy link

Hello, I'm not senthilraj and some months lasted since you posted the answer, but I also wanted to use custom divider and I found a solution.
Option is format_output and it accepts a function like that:

function(tim, mini, meri) {
                if(settings.show_meridian){
                    return tim + " : " + mini + " : " + meri;
                }else{
                    return tim + " : " + mini;
                }
            }

This is default one, you can find it at top of plugin source js. However, in that contest we don't have settings variable, so if you don't need the spaces and want 24h format, like me, you can modify it in this way:

function(tim, mini, meri) {
                return tim + ":" + mini;
        }

Hope it helps you or any lurker!

@jonasferagen
Copy link

Hi, and thanks for a great plugin!

I had the exact same problem and made a hack for a format_string option (syntax like strftime)
https://github.com/chroz/TimePicki
i - i.e. the current default is %H : %M : %p,
i override this in my pickers with "%H:%M"

It's way too hackish to be worthy of a pull request, but I think something like this could be the way to go, maybe making the show_meridian option implicit in the future?

@seleckis
Copy link
Author

Thank you for your replies, guys, but these hacks do not resolve the issue. I need to set default value from backend. Using your solution, I have to generate JS code right in the HTML, or load it via AJAX. It is nightmare. I have already moved to https://eonasdan.github.io/bootstrap-datetimepicker/, which solves this problem, but unfortunately it needs bootstrap.

@cefrigo
Copy link

cefrigo commented Aug 4, 2016

I made this it works fine...

function getTimepickiTime(obj) {
    var TimeValue = obj.val();
    var trimmedTimeValue = TimeValue.replace(/ /g,'');
    var resultSplit = trimmedTimeValue.split(':');
    return resultSplit;
};
   $('.timepicker_start').timepicki({
         start_time: getTimepickiTime($('.timepicker_start'))
     });

This will take the value of the input and use it as default

@repler
Copy link

repler commented Jan 30, 2017

I know this thread is kind of old, but you can set the default value through HTML by specifying the following attributes on your input tag:

data-timepicki-tim
data-timepicki-mini
data-timepicki-meri

For hours, minutes, and meridian, respectively.
Works just fine without any code changes.

@Istiak1992
Copy link

i want to pop up an alert when i change time when value is changed in the textbox i want an alert pop up.how can i accomplish this?

@Lataoodles
Copy link

@Istiak1992
You can use this method
$("#timepicker1").on('click',function(){
alert("Hi")
})

@jaimestuardo
Copy link

jaimestuardo commented Jun 19, 2020

I have fixed it by changing code in line 407 of timepicki.js to this:

		var value = ele[0].value.replace(/ /g, '');
		if (value.length === 0) {
			d = new Date();
			ti = d.getHours();
			mi = d.getMinutes();
		}
		else {
			ti = parseInt(value.substr(0, 2));
			mi = parseInt(value.substr(3, 2));
                    }

Regards
Jaime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants