Is there a way to make the X-editable datepicker appear next to the date field rather than in the same spot every time?

When utilizing X-editable, I encountered a problem where specifying the datepicker field mode as "popup" results in the popup displaying correctly. However, when dealing with a long table (either vertically or horizontally), the position of the date/datetime picker popover becomes an issue. It consistently pops up at a fixed location on the page (top left).

For instance, if there are 50 records and I click on one towards the end of the list to trigger the date picker, the popover might appear off-screen. In such cases, I have to scroll all the way back to the top of the table just to see it.

The situation worsens when working with tables that extend far to the right on smaller screens. To view the opened popover, you would need to scroll all the way back to the left. This behavior might lead to confusion and make it seem like the script is malfunctioning.

Here is how I have defined it - could I be missing something here? Or is it perhaps related to CSS?

$('.time').editable({
    type: 'datetime',
    url: 'post.php',
    format : 'yyyy-mm-dd hh:ii',
    viewformat : 'yyyy-mm-dd hh:ii',
    inputclass : "datepick",
    emptytext: '...',
    datetimepicker : {
        weekStart : 1
    },
});

Answer №1

Indeed, there is a longstanding issue with tooltip and popup positioning.

Here is a helpful trick you can try:

$('.time').editable({
    type: 'datetime',
    url: 'post.php',
    format : 'yyyy-mm-dd hh:ii',
    viewformat : 'yyyy-mm-dd hh:ii',
    inputclass : "datepick",
    placement: function (context, source) {
      var popupWidth = 336;
      if(($(window).scrollLeft() + popupWidth) > $(source).offset().left){
        return "right";
      } else {
        return "left";
      }
    },
    emptytext: '...',
    datetimepicker : {
      weekStart : 1
    },
});

Feel free to check out a working example here: http://jsfiddle.net/giftedev/yo0ztmkr/1/

Answer №2

Issue Explanation

To clarify, it seems that you are dealing with a lengthy table filled with fields that users need to complete (similar to this demonstration page). As you scroll through this table and click on a field, the corresponding pop-up appears far above on the page. Is my understanding correct so far? If it is...

I have examined how X-editable generates these pop-ups. The primary method it utilizes is as follows:

  • It creates a div (the primary container) and attaches it right after the node that triggers the pop-up.
  • This div uses an absolute position with specified top and left values.
  • The values for top and left are calculated by a recursive function that adds the offsetX and offsetY of its parent elements recursively.

This approach of displaying a pop-up div is quite common and functions effectively in all scenarios.


Possible Reasons for this Issue

Where might the problem lie?

  • Library Codes: It seems unlikely that the bug resides in the X-editable codes, as I modified the HTML codes in the demo page using Firefox Developer Tools and changed the row heights to a significantly large number (1000px), yet the pop-ups continued to appear in their correct positions.

  • Your Custom Codes: This is the more probable culprit. I observed that this library employs several class names for its main pop-up div, such as popover, editable-container, editable-popup, fade, in, and right. These names could potentially clash with your own defined classes and result in unexpected behavior in the pop-ups, such as overriding the absolute position with a relative one. Therefore, ensure that your CSS class names differ from those set by X-editable.

I am unable to provide more specific guidance without reviewing your HTML codes. If my insights did not address your issue, please furnish additional information about the problem at hand.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a vibrant rectangle using date coordinates

I am seeking a solution to draw dynamic rectangles based on date coordinates. Extracting the x & y-axis information from the date is crucial for this task. So far, I have experimented with three different approaches: The first approach involved using t ...

Using a width of 100% with the display inline-block property does not function as intended

Is there a way to have both a checkbox and text input in one line, with the text input being responsive? I attempted to use display: inline-block, which worked for keeping them in the same line, but I'm having trouble making the text input fill the re ...

Having trouble extracting data from Moz Bar through selenium using Python?

Having trouble retrieving the spam score from Moz bar using Selenium WebDriver? I've attempted various methods such as XPath, class, and tag name without success. Any assistance would be greatly appreciated: from selenium.webdriver.common.by import By ...

What is the most effective method of verifying image loading?

Currently, I am utilizing the mjpeg format to display a stream from an IP camera. However, I have been experiencing issues with the stability of the stream. The problem lies in not knowing when exactly the stream begins and, therefore, requiring a check on ...

Leveraging the power of Ajax to dynamically submit a single form nested within a forEach iteration

I'm currently working on a database query that retrieves all user posts. This query is then used in a forEach loop to generate a post for each result: for($indexPost=0; $indexPost < $postCount; $indexPost++) { //Code for handling the post echo&l ...

Using ajax to retrieve data by applying multiple criteria

Currently, I am utilizing AJAX to retrieve database data and compare it with a variable in order to display the information. At the moment, I am only comparing based on one condition in the "Where" clause, specifically whether the field ID is equal to a ...

"Enhanced jQuery confirmation dialog plugin with full screen functionality and automatic

My current web-based production tracking system isn't getting the attention it needs from users, so I'm in the process of creating a full-screen alert and confirm function to ensure they pay closer attention. The idea is for alerts to remain on t ...

Creating a CSS grid layout with a scrollbar positioned on the left side and content filling from left to right

How can I move the scrollbar to the left while keeping ng-repeat population from left to right? I'm using an ng-repeat to fill a grid that is 3 by X (Width by height). By default, the scroll bar appears on the right side. I want to position it on the ...

Centered Alignment for Bootstrap Carousel Captions

I'm attempting to make a simple change here. Rather than having the Bootstrap Carousel Captions automatically align at the bottom of the Carousel, I would like them to align at the top by default. Any suggestions on how I can achieve this? ...

Using Bootstrap's card component, design a grid layout for your website

I am attempting to construct a grid using the Bootstrap 4 card component. After reviewing the documentation and utilizing the card-deck feature, I aim to have each row consist of two columns with the behavior similar to col-12 col-md-6. Additionally, the s ...

Prevent background image animation in CSS

I've encountered an issue with a simple button I created that uses two background images for normal and hover states. Upon testing in various browsers, I noticed that the images animate on hover, causing them to slide up and down. I tried eliminating ...

"Stuck: CSS Div Transition Effect Refuses to Cooper

I am looking to incorporate a transition on my div when it is clicked. I've tried using jQuery with this example: http://jsfiddle.net/nKtC6/698/, but it seems to not be working as expected. So, I want to explore another example using CSS: http://jsfid ...

A comprehensive guide to effectively formatting Recharts in React: addressing alignment and size management!

While attempting to style two graphs as floating cards, I am encountering difficulties in controlling the sizing and centering of the graphs. Specifically, I am having trouble with the pie chart in this example. To address this issue, I am passing paramete ...

Create a Boostrap navbar with a form and links aligned to the right using the navbar

I'm trying to use navbar-right on a navbar-form and a navbar-nav, but the form ends up on one row and the nav links on another row on the right. How can I make the navbar display the brand on the left and have a search field followed by nav links on t ...

What is the best way to ensure text starts on a new line when paragraphs and images are floating and aligned?

Does anyone have a clearer title idea? Feel free to edit. To better illustrate my point, I've created a jsfiddle. I am working with a simple layout of text and images. My goal is to make the second text and image appear on a new row just below the f ...

What is the proper sequence for binding jQuery to elements?

I'm currently facing a challenge with using jQuery to link a function to an element. Essentially, I'm loading a series of divs via JSON, with each item in the JSON having an "action" assigned to it that determines which function should be trigger ...

Utilizing jQuery to update dropdown selection based on JSON object values

In my JSON value, I have the following roles: var roles = { "roles":[ {"role_id":2,"role_name":"admin"}, {"role_id":4,"role_name":"QA"}, {"role_id":3,"role_name":"TL"}, {"role_id":5,"role_name":"user"}, {"role_id":1,"role_name":"r ...

What is the best way to extend the final column of a table across the entire width?

Here's the code I'm working with: .frm-find-people table td:nth-child(1) { padding: 5px 15px; width: 100px } .frm-find-people table td:nth-child(2) { border: 1px solid red; } <form class="frm-find-people"> <table> ...

Activate the counter as soon as the error message appears

To effectively track the number of errors generated upon form submission, I require a counter mechanism. The errors are identified by the CSS class .validmissing. For instance, if a user encounters 5 errors upon submitting the form, the counter should be ...

In Javascript, an error occurs when something is undefined

I've been grappling with a Javascript issue and seem to have hit a roadblock. In Firefox's console, I keep encountering an error message that says "info[last] is undefined," and it's leaving me puzzled. The problematic line appears to be nu ...