Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

date picker - bootstrap and moment_datepicker

Posted on 2016-07-20
3
96 Views
Last Modified: 2016-07-22
I have a datepicker implemented using Bootstrapv2.3.1 and moment.js / moment_datepicker.js (version 2.50)

It's tricky to post any sort of jsfiddle since it is an ASP.NET web user control (ascx).

I believe this is a CSS issue, I just am not sure how to override the cascade provided by bootstrap without interfering with bootstraps look and other functionality.

Basically, I want to have a "clear text" button which clears the date value chosen by the picker.  Sometimes it is desirable to not have any value chosen for the date, but if you accidentally choose a date, the date picker seems to provide no way to unpick the date or set it to Nothing.

As far as layout, I want the button to be on the same "row" as the text input and the datepicker icon.  Right now if I put it in the same div as the datepicker icon button, the button no longer clears the text, it invokes the date picker.  I think this is because one it is put inside the div - the bootstrap CSS overrides the button behavior.  I need it to still apply the bootstrap styling, but not interfere with the button's functionality.

web user control:

<%@ Control Language="vb" AutoEventWireup="true" CodeBehind="uc_DatePicker.ascx.vb" Inherits="DealerSocket.Web.uc_DatePicker" EnableViewState="true" %>

<script src="../javascript/datePicker.js"></script>
<script src="../javascript/date.js"></script>
<script src="/ReportEngine/js/moment.js" type="text/javascript"></script>
<script src="/Assets/Moment/Datepicker/moment-datepicker.js"></script>
<link href="/Assets/Moment/Datepicker/datepicker.css" rel="stylesheet" />
<style type="text/css">
    .datepicker.dropdown-menu {
        min-width: 246px !important;
        padding-left: 10px !important;
    }

    .switch {
        background: white none repeat scroll 0 0 !important;
    }

    .datepicker th.switch {
        width: 170px !important;
    }

    .datepicker-days .table-condensed tr td:hover {
        background-color: #DCEDF7 !important;
    }

    .datepicker table tr td.active, .datepicker table tr td.active:hover {
        background-image: -moz-linear-gradient(center top, hsl(200, 80%, 40%), hsl(193, 80%, 40%));
        background-image: -ms-linear-gradient(top, hsl(200, 80%, 40%), hsl(193, 80%, 40%));
        background-image: -webkit-linear-gradient(top, hsl(200, 80%, 40%), hsl(193, 80%, 40%));
    }

    
    .blahblah { 
        width:300px;         
        border:1px solid red;  
    }

</style>


<asp:Literal ID="capti" runat="server" Text="<%= Me.CaptionText %>" />

<div class='input-group date blahblah' id='divDatePicker' runat="server" onclick="javascript:openDatepicker(this);">
    <asp:TextBox ID="IntntlDatePick" ReadOnly="true" CssClass="form-control" ClientIDMode="Static" Text="" TextMode="DateTime" autocomplete="off"  onclick="javascript:DatePickerRefreshState($(this).attr('id'),'Visible');" runat="server" />
    <span class="input-group-addon" style="cursor: pointer;">
        <span class="fa fa-calendar"></span>        
    </span>  


IF I PUT THE "CLEAR BUTTON" HERE, IT NO LONGER CLEARS THE DATE PICKER VALUE, INSTEAD IT INVOKES THE DATE PICKER    
    
</div>


THIS IS THE CLEAR BUTTON:

<span id="clrparen" class="input-group-addon" style="cursor: pointer; width:13px;" onclick="javascript:ClearButtonRefreshState($(this).children().attr('id'), 'Visible');">
        <span style="width:13px; cursor: pointer;" id="clrbtn" class="fa fa-eraser" onclick="javascript:ClearButtonRefreshState($(this).attr('id'),'Visible');" runat="server"></span>
</span>  

Open in new window


screenshot:

clear button
0
Comment
Question by:knowlton
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 500 total points
ID: 41722187
More than likely the problem is in that some definition in the other CSS files for the page is conflicting or overriding the css you have here. The only way to determine or even guess an answer to this is to look at the CSS for all the elements at play here. There just isn't enough information here to work from. Can you post a link to the page in question?
0
 
LVL 5

Author Comment

by:knowlton
ID: 41725240
Final solution:

<div class='input-group date' id='divDatePick' style="width: 100%;" runat="server">    
        <asp:TextBox ID="IntntlDatePick" CssClass="form-control" ClientIDMode="Static" Text="<%= Me.DateText %>" TextMode="DateTime" autocomplete="off" onclick="javascript:DatePickerRefreshState($(this).attr('id'),'Visible');" runat="server" />
        <span class="input-group-addon" style="cursor: pointer;" onclick="javascript:openDatepicker(this);">
            <span class="fa fa-calendar"></span>
        </span>    

        <span id="clrparen" class="input-group-addon" style="cursor: pointer; width: 13px;" onclick="javascript:ClearButtonRefreshState($(this).children().attr('id'), 'Visible');">
            <span style="width: 13px; cursor: pointer;" id="clrbtn" class="fa fa-eraser" onclick="javascript:ClearButtonRefreshState($(this).attr('id'),'Visible');" runat="server"></span>

        </span>
</div>

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 41725242
Thanks!
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question