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>
Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Shimrod
  • 3,115
  • 2
  • 36
  • 56

7 Answers7

10

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

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

Try it

iPaul
  • 423
  • 1
  • 7
  • 22
6

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.

Stefan Svrkota
  • 48,787
  • 9
  • 98
  • 87
  • Hi Stephan. Thanks for your anwser. I tried but unfortunatly it still show a bug, like you can see here: http://i.imgur.com/rkjyel0.png The code I used is `
    `
    – Shimrod Nov 04 '16 at 13:07
  • @Shimrod I see, but that's whole another problem caused by `[showIcon]="true"`. Consider using `placeholder` or something instead of it. – Stefan Svrkota Nov 04 '16 at 17:46
3
  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;
}
Mina Matta
  • 1,024
  • 14
  • 22
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>
louisl
  • 99
  • 1
  • 10
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>
Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
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"
Amit Soni
  • 3,216
  • 6
  • 31
  • 50
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

YoungHobbit
  • 13,254
  • 9
  • 50
  • 73