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

Use jQuery UI Position for positioning the Datepicker #41

Closed
SunboX opened this issue Apr 2, 2015 · 5 comments
Closed

Use jQuery UI Position for positioning the Datepicker #41

SunboX opened this issue Apr 2, 2015 · 5 comments

Comments

@SunboX
Copy link

SunboX commented Apr 2, 2015

Use jQuery UI's Position class for positioning the Datepicker relative to the Textfield. This is more flexible. You could even choose another element to position against.
This also saves a lot (!) of positioning logic in the zebra_datepicker.js

Demo: https://jqueryui.com/position/
API Docs: http://api.jqueryui.com/position/

So, the setting:

$('.datepicker').Zebra_DatePicker({
    default_position: 'above'
});

will translate to:

$('.datepicker').Zebra_DatePicker({
    position: {
        my: "left bottom",
        at: "left top"
    }
});

And this setting:

$('.datepicker').Zebra_DatePicker({
    default_position: 'below'
});

will translate to:

$('.datepicker').Zebra_DatePicker({
    position: {
        my: "left top",
        at: "left bottom"
    }
});
@bellsolve
Copy link

Is this still supposed to work? I would like to position the datepicker below the input box but using the following doesn't work. Have I missed something.

$('.datepicker').Zebra_DatePicker({
    position: {
        my: "left top",
        at: "left bottom",
        of: ".datepicker"
    }
});

Thanks

@stefangabos
Copy link
Owner

stefangabos commented Sep 27, 2023

this post was about a suggestion that zebra datepicker to use jQuery UI for positioning
zebra datepicker doesn't use jQuery UI for positioning
as per the docs, you might want to use

$('.datepicker').Zebra_DatePicker({
    default_position: 'below'
});

@bellsolve
Copy link

Thanks for your reply. Apologies I misinterpreted the post.

I tried default_position but that moves the datepicker relative to the cursor when what I am looking for is relative to the input.

default_position: 'below' looks like this:

image

I would like it to look like the image below which is taken from an old site that used a version of the datepicker from 2012.

image

Can that be done.

Thanks

@stefangabos
Copy link
Owner

i just pushed version 2.0.0 of the datepicker. with that you can do this

$('.datepicker').Zebra_DatePicker({
    onOpen: function() {
        var properties = this.data('Zebra_DatePicker'),
            $datepicker = properties.datepicker,
            $parent = $(this),
            parent_position = $parent.offset(),
            parent_height = $parent.outerHeight();
            
        $datepicker.css({
            left: parent_position.left,
            top: parent_position.top + parent_height + 5
        });
    }
});

note that the plugin always tries to keep the datepicker inside the view port so it will auto-arrange it if necessary. with this hack that functionality is suppressed

I will look into adding more default positionings options though

@bellsolve
Copy link

Yes, that worked, exactly what I needed. Thanks for your prompt response.

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

3 participants