PrimeNG calendar error when applying css class from bootstrap

I have this strange error when I use PrimeNG to display DatePicker in my application. When I try to use bootstrap form-control , I get a visual error.

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 this is 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> 
+5
source share
6 answers

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

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

So this behavior is not an error , it is the expected behavior because you are using the wrong attribute. If you want to add a form-control class to the PrimeNG calendar input field, you should use inputStyleClass instead of the 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 the entire list of attributes for the PrimeNG calendar component here .

+4
source

I used the workaround below and this works fine in both IE and Chrome:

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

Try

+4
source

Addition to @Srefan Svrkota answer. You can create another css class that overrides the inline style of the form-control class. .showCalenderInline {display: inline! important; }

and apply to the calendar: inputStyleclass = "form-control showCalenderInline"

0
source
  • use the " inputStyleClass " property to set the css class

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

  1. If you are not using an Inline form, override the < ui-calendar "css class
 .ui-calendar { display: block; } 
0
source

Adding this css worked for me to get the icon in place, and also add the 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> 
0
source

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

add styleClass and inputStyleClass as follows:

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

and try changing 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 result enter image description here

-1
source

All Articles