Ionic 2 - Setting min and max attribute to ion-datetime - ionic-framework

I know this seems easy, but I could not find any answers for my question.
How can I set the min and/or max attributes to ion-datetime, but only for time picker?
<ion-row>
<ion-col no-padding>
<ion-item no-padding>
<ion-label floating>Time In:</ion-label>
<ion-datetime pickerFormat="hh:mm A" [(ngModel)]="ptReEvaluation.content.iprTimeIn"></ion-datetime>
</ion-item>
</ion-col>
</ion-row>

please try it
<ion-row>
<ion-col no-padding>
<ion-item no-padding>
<ion-label floating>Time In:</ion-label>
<ion-datetime pickerFormat="hh:mm A" [(ngModel)]="ptReEvaluation.content.iprTimeIn" in="2016" max="2020-10-31"></ion-datetime>
</ion-item>
</ion-col>
</ion-row>
i hope its work for you.

You should try this. In file.ts, declear
private minyear : string = (new Date().getFullYear()-1).toString();
private maxyear : string = (new Date().getFullYear()+1 + '-' + new Date().getMonth()+1 + '-' + new Date().getDate()).toString();
And in html side include as
<ion-datetime displayFormat="DD-MM-YYYY" pickerFormat="DD-MM-YYYY" [(ngModel)]="filter_param.start_date" placeholder="From" (ionChange)="validate_date_range()" [min]="minyear" [max]="maxyear"></ion-datetime>
<ion-datetime displayFormat="DD-MM-YYYY" pickerFormat="DD-MM-YYYY" [(ngModel)]="filter_param.end_date" placeholder="To" (ionChange)="validate_date_range()" [min]="minyear" [max]="maxyear"></ion-datetime>
I have put code on my conditions, you can append it to, with your requirements.

I tried this approach to get my bug cracked after crushing 6-7 days. In my case, I have to pass the getMinimum value as the minimum time while checking out. So users should not be able to check-out before the check-in time.
.ts File
check_in_value: 2021-12-06T13:15:11.684Z
const a = parseISO(check_in_value);
const b = addHours(new Date(a),5);
this.getMinimum = b.toISOString()
concole.log(this.getMinimum)
HTML File
<ion-datetime
displayFormat="YYYY-MM-DD HH:mm"
pickerFormat="YYYY-MM-DD HH:mm"
[value]="check_out"
[min]="getMinimum3"
></ion-datetime>
Important Notes:
The Displaying Format plays an important factor in rendering the Date and Time. Read the documentation thoroughly. “Ionic Framework uses the ISO 8601 datetime format for its value”. Link: ion-datetime: Ionic API Input for Datetime Format Picker
“Exactly the components shown here must be present, with exactly this punctuation” Link: https://ionicframework.com/docs/api/datetime?_gl=1*1lg7t6u*_ga*MTk3MzQ4NzM5Ny4xNjQxODg2ODQy*_ga_REH9TJF6KF*MTY1MDMyNDM1MS4xMTIuMS4xNjUwMzI2NjU0LjA.
“Exactly the components shown here must be present, with exactly this punctuation” Link: https://www.w3.org/TR/NOTE-datetime

Related

Trigger ionChange when select value is the same

I have 1 ion-datetime and 1 ion-select. Based on what is selected for ion-datetime, it will call backend API to retrieve values for ion-select. The date selected can be the same, but based on the API submission timing, the date returned back can be different.
<ion-item >
<ion-label>Date: </ion-label>
<ion-datetime class="dateInput" displayFormat="MMM DD YYYY"
[(ngModel)]="dateList" (ionChange)="retrieveValues()">
</ion-datetime>
</ion-item>
<ion-item>
<ion-label>Values: </ion-label>
<ion-select [(ngModel)]="valueList" (ionChange)="changeValue()">
<ion-select-option*ngFor="let value of valueList" [value]="value">{{value}}
</ion-select-option>
</ion-select>
</ion-item>
How do I trigger (ionChange)="retrieveValues()" even if the date selected is the same? Currently it only runs when the selected date is different from previous.

Currency masking in ionic

I am trying to format the entry in currency format like 10,000.00 in a ion-input field with the below line of code but while entering the text it shows the output as 10,000.0010000. I have tried almost all of the alternate solutions in online and none of them helped me to overcome this situation. tried ng2-currency-mask and its not working
<ion-item>
<ion-input type="number" [(ngModel)]= Basic pattern="\d*" name="Basic"
#Basic="ngModel" clearInput placeholder="0.00">
<div>{{selectedCtcBasic | currency: '₹ '}}</div>
</ion-input>
<div class="error-form" *ngIf="Basic.invalid">
<div *ngIf="Basic.errors.pattern">* Text/symbols not allowed</div>
</div>
</ion-item>
Basically currency masks and directives are applied to input element, but when you use <ion-input>, then you can observe by inspecting element that its not input there's some other tags are also added. So you need to add these type of things on input element as shown below -
<ion-item>
<input type="number" [(ngModel)]="selectedCtcBasic" name="Basic"
#Basic="ngModel" clearInput placeholder="0.00" />
<div>{{selectedCtcBasic | currency: '₹ '}}</div>
</ion-item>
Happy Coding :)

How to get rid of the cick delay. It takes like 2 seconds in Ipad

This is my sample code, It takes like 2 seconds for the changes to happen
<ion-row *ngFor="let week of month.fullweeks; let weekindex =index" style="margin-bottom:5px;">
<ion-col *ngFor="let day of week;let i = index" tappable (click)="selectday(day,monthindex,i,weekindex)" >
<div class="day" [ngClass]="{'startactive':(day.style == 1),'finishactive':(day.style == 2)}" ><div *ngIf="day.day != 0" >{{day.day}}</div></div>
</ion-col>
</ion-row>
Managed to solve this by updating Ionic Scripts and not using inline css

Ionic2 - Error - If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone'

I'm not sure to understand the error I'm getting while looping through an array of options to populate my select list.
Here is the error I get
Error in ./PhonePage class PhonePage - caused by:
If ngModel is used within a form tag, either the name attribute must be set or the
form control must be defined as 'standalone' in ngModelOptions.
Example 1: <input [(ngModel)]="person.firstName" name="first">
Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
Here is my html code
<form>
<h2>Quel est votre numéro de téléphone?</h2>
<ion-list>
<ion-grid>
<ion-row>
<ion-col width-33>
<ion-item>
<ion-select [(ngModel)]="optionList">
<ion-option *ngFor="let item of optionList" value="{{item.text}}">{{item.text}}</ion-option>
</ion-select>
</ion-item>
</ion-col>
<ion-col>
<ion-item>
<ion-input type="text"></ion-input>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
</ion-list>
</form>
Prerak Tiwari's answer is correct.
Here is just a little tip: I see you bind your ion-select to "optionList" but this is just the list of options you want to show and need to create all ion-options.
You should bind the ion-select to a new parameter, because aftewards it will hold the selected ion-option.
If ngForm is used, all the input fields which has [(ngModel)]="" must have a attribute name with a value.

How to set various attribute of DOM element from variable angular 2?

In my app I have variable of String. Which is have in string name of attribute to add.
ngOnInit()
{
this.colAttibute = 'width-50';
}
or it can be equal to 'width-100'. My app is get device width and set the value of this variable on onNgInit method.
I want to set this attribute to my html code something like that:
<ion-list no-lines *ngIf="list">
<ion-list-header>
Лидеры продаж
</ion-list-header>
<ion-item class="categoryProductItem" *ngFor="let row of list;">
<ion-row wrap >
<ion-col *ngFor="let product of row" $colAttibute > <!--Here must be width-50 or width-100 attribute-->
<a ion-item detail-push (click)="onSelectItem(product)" >
<div class="categoryProductItemImage" *ngIf="product.getMainImage()">
<ion-img [src]="product.getMainImage()['small_url']"></ion-img>
</div>
<h2>
{{product.title}}
</h2>
</a>
</ion-col>
</ion-row>
</ion-item>
</ion-list>
How to do this?
You can set the width like this:
<ion-col [attr.width-70]="flag">
Where flag is a boolean value indicating whether to apply this attribute or not.
Unfortunately, you will need to list all the available attributes in order to support all of them dynamically.