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:
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>
I have used the below workaround, and this is working fine in both IE & Chrome:
<p-calendar [inputStyle]="{'width':'55%'}" ...
Try it
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 .
inputStyleClass
" property to set the css class
<p-calendar inputStyleClass="form-control"></p-calendar>
ui-calendar
" css class.ui-calendar { display: block; }
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>
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"
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
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.