PrimeNG calendar bug when applying css class from bootstrap
Asked Answered
U

7

12

I have this strange bug where I use PrimeNG to display a DatePicker in my application. When I try to use bootstrap's form-control, I get a visual bug.

Here is my template:

<div class="form-group row">
    <div class="form-group col-md-2">
        <label for="valeur">Valeur</label>
        <input type="number" id="valeur" class="form-control" />
    </div>

    <div class="form-group col-md-5">
        <label for="dateDebut">Date de début</label>
        <p-calendar id="dateDebut" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>

    <div class="form-group col-md-5">
        <label for="dateFin">Date de fin</label>
        <p-calendar id="dateFin" dateFormat="dd/mm/yy" styleClass="form-control" [showIcon]="true"></p-calendar>
    </div>
</div>

This is the result:

enter image description here

EDIT

If it's of any help, here is the generated HTML:

<div class="form-group col-md-5" _ngcontent-scp-1="">
   <label for="dateDebut" _ngcontent-scp-1="">Date de début</label>
   <p-calendar ng-reflect-show-icon="true" ng-reflect-date-format="dd/mm/yy" ng-reflect-style-class="form-control" styleclass="form-control" id="dateDebut" dateformat="dd/mm/yy" _ngcontent-scp-1="">
      <!--template bindings={
         "ng-reflect-ng-if": "true"
         }-->
      <span ng-reflect-initial-classes="form-control" class="form-control ui-calendar" ng-reflect-raw-class="ui-calendar">
         <input id="dp1467976345328" ng-reflect-value="" class="hasDatepicker ui-inputtext ui-widget ui-state-default ui-corner-left" ng-reflect-raw-class="[object Object]" type="text"><!--template bindings={
            "ng-reflect-ng-if": "true"
            }--><button ng-reflect-icon="fa-calendar" type="button" pbutton="" class="ui-datepicker-trigger ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"><span class="ui-button-icon-left ui-c fa fa-fw fa-calendar"></span><span class="ui-button-text ui-c">ui-button</span></button>
      </span>
      <!--template bindings={
         "ng-reflect-ng-if": "false"
         }-->
   </p-calendar>
</div>
Uproarious answered 8/7, 2016 at 11:16 Comment(6)
Possibly Bootstrap's form-control has a view styles colliding with PrimeNG's input/form layout?Berndt
I added the generated htmlUproarious
Its exactly the same problem I reported on PrimeNG forum forum.primefaces.org/…Lothair
Thanks @AJQarshi , maybe it will be adressed (even if they don't seem very active on the forum...)Uproarious
@AJQarshi Don't know if you're still having problems with this, just wanted to let you know that I provided solution.Arman
For info - Primefaces calendar component shows similar behavior and works as expected if we apply form-control to inputStyleClass attribute.Pneumatology
N
10

I have used the below workaround, and this is working fine in both IE & Chrome:

<p-calendar [inputStyle]="{'width':'55%'}" ...

Try it

Neufer answered 1/9, 2017 at 11:57 Comment(1)
Working for me. Thx!Taxation
A
7

PrimeNG's calendar component has four styling attributes, two for adding inline styles and two for adding style (css) classes - style, styleClass, inputStyle and inputStyleClass.

  • style and styleClass are used to style the component itself (calendar)
  • inputStyle and inputStyleClass are used to style input field

So, this behaviour is not a bug, it's expected behaviour because you are using wrong attribute. If you want to add form-control class to PrimeNG's calendar input field, you should use inputStyleClass instead of styleClass attribute:

 <div class="form-group col-md-5">
    <label for="dateFin">Date de fin</label>
    <p-calendar id="dateFin" dateFormat="dd/mm/yy" inputStyleClass="form-control" [showIcon]="true"></p-calendar>
</div>

Check entire list of attributes for PrimeNG's calendar component here.

Arman answered 3/11, 2016 at 23:50 Comment(2)
Hi Stephan. Thanks for your anwser. I tried but unfortunatly it still show a bug, like you can see here: i.imgur.com/rkjyel0.png The code I used is <div class="form-group"><p-calendar id="dateDebut" dateFormat="dd/mm/yy" inputStyleClass="form-control" [showIcon]="true"></p-calendar></div>Uproarious
@Uproarious I see, but that's whole another problem caused by [showIcon]="true". Consider using placeholder or something instead of it.Arman
P
4
  1. use "inputStyleClass" property to set the css class

<p-calendar inputStyleClass="form-control"></p-calendar>

  1. If you are not using Inline form, then override the "ui-calendar" css class
.ui-calendar {
    display: block;
}
Pelvic answered 16/6, 2017 at 20:29 Comment(0)
T
3

Adding this css worked for me to get the icon in place as well as adding form-control to the inputStyleClass attribute.

.ui-calendar button {
    right: 0;
    top: 0;
}
.ui-calendar {
    width: 100%;
}

<p-calendar dateFormat="dd/mm/yy" showTime="showTime" hourFormat="24" formControlName="start" [showIcon]="true" inputStyleClass="form-control"></p-calendar>
Trier answered 3/8, 2017 at 16:10 Comment(0)
A
1

Primeng 11 / Bootstrap 4.

Adapt CSS:

.p-calendar {
  width: 100%;
  height: 36px;
}

No need for setting styleClass on the p-calendar:

<div class="form-group col-md-5">
    <label for="dateFin">Date de fin</label>
    <p-calendar inputId="dateFin" dateFormat="dd/mm/yy" [showIcon]="true"></p-calendar>
</div>
Aubade answered 29/3, 2021 at 14:29 Comment(1)
it worked kool snippetTrevino
B
0

Addition to @Srefan Svrkota's answer. You can make another css class that overwrites the form-control class's inline style.

    .showCalenderInline
    {
    display: inline !important;
    }

and apply to calendar : inputStyleClass="form-control showCalenderInline"
Bias answered 2/12, 2016 at 15:42 Comment(0)
H
0

Hi guys maybe you can try this. im using this for my code

add styleClass and inputStyleClass like this:

<p-calendar styleClass="form-control" inputStyleClass="form-control" ></p-calendar>

and try to change some css, for me like this :

.ui-inputtext{ margin:-7px -12px; }

.ui-button, button.ui-button.ui-state-default, .ui-button.ui-state-default{ top:0px; right: -1px; }

.ui-calendar button{ width: 2.5em; }

and the result is enter image description here

Hitchcock answered 6/1, 2017 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.