<ion-grid>
<ion-item>
<ion-label col-5 inline>Building Type</ion-label>
<ion-select type="text" formControlName="ml_build_type">
<ion-option value="VILLA">Villa</ion-option>
<ion-option value="BLGD">Building</ion-option>
</ion-select>
</ion-item>
<ion-row>
<ion-item col-6 inline>
<ion-label >Name/Number</ion-label>
<ion-input type="text" formControlName="ml_build" ></ion-input>
</ion-item>
<ion-item col-6 inline >
<ion-label >Flat No</ion-label>
<ion-input type="number" formControlName="ml_flat" ></ion-input>
</ion-item>
</ion-row>
<ion-row>
<ion-item col-6>
<ion-label inline> Floor No</ion-label>
<ion-input type="number" min="0" formControlName="ml_floor" ></ion-input>
</ion-item>
<ion-item col-6>
<ion-label inline>Room No</ion-label>
<ion-input type="number" min="0" formControlName="ml_room_no" ></ion-input>
</ion-item>
</ion-row>
<ion-row>
<ion-item col-6>
<ion-label inline>Room Type</ion-label>
<ion-select type="text" formControlName="ml_unit" >
<ion-option *ngFor="let room of room_type" let i=i ndex [value]="room.code">{{room.room_type}}</ion-option>
</ion-select>
</ion-item>
<ion-item col-6>
<ion-label inline> Wall Number</ion-label>
<ion-input type="number" min="0" formControlName="ml_wall_no" ></ion-input>
</ion-item>
</ion-row>
<ion-row>
<ion-item col-6>
<ion-label inline> Wall Width</ion-label>
<ion-input type="number" formControlName="ml_width" ></ion-input>
</ion-item>
<ion-item col-6>
<ion-label inline> Wall Height</ion-label>
<ion-input type="number" formControlName="ml_height" ></ion-input>
</ion-item>
</ion-row>
<ion-item>
<ion-label col-5 inline>Window Exists</ion-label>
<ion-select formControlName="window_exists" type="text">
<ion-option value="Y">Yes</ion-option>
<ion-option value="N">No</ion-option>
</ion-select>
</ion-item>
</ion-grid>
this HTML code , the data is displaying according to lable size, i want them to look good and arranged in one line, All data must be display in horizontal alignment . i am trying to use as much as ionic component to make it look perfect but the data is displaying here and there.
In the .scss file for your page, you can override the Ionic label style thus to make the labels all the same width:
.item-input ion-label {
width: 150px;
}
You just have to choose a width that suits your layout and accommodates all label widths.
Ionic provides several attributes that allow you to control the styling for inputs. You probably want to use the Fixed Inline Labels.
Excerpted from Input Component Documentation emphasis added
Use fixed to place a label to the left of the input element. The label does not hide when text is entered. The input will align on the same position, regardless of the length of the label. Placeholder text can be used in conjunction with a fixed label.
Replace inline in your code with fixed.
<ion-item col-6>
<ion-label fixed> Wall Width</ion-label>
<ion-input type="number" formControlName="ml_width"></ion-input>
</ion-item>
EDIT
If you have very long labels and you can't shorten them, your options are:
1. Override the label width:
If you have static labels, you can override the label width of the fixed width labels. Fixed width labels by default are 100px wide. To set them to 200px for example, add the following to your scss file:
ion-label[fixed] {
width: 200px;
flex: 0 0 200px;
//max-width defaults to 200px
//if you're setting your label width wider than 200px
//remember to adjust the max-width as well.
}
2. Toggle the overflow property of the ion-label.
The ion-label has its overflow property set to overflow: hidden. You could set the value to visible, and then programmatically change it to hidden when the respective input is in focus or has a value that is not empty. This way the ellipsis for the label will only appear once the input has been entered and given a value.
A simple way to do this is with ngStyle. To determine if the input as focus, you could add a property to your class, setting its initial value to false, and then toggle the value by adding focus/blur events to the corresponding input as follows:
<ion-input (focus)="inFocus = true" (blur)="inFocus = false" ...>...</input>
Then you can use ngStyle to toggle the overflow value by determining whether the inFocus property is true or the input is not empty (by observing the ngModel for the input). So, you'd have something like:
<ion-label [ngStyle]="{'overflow': inFocus || myForm.myinputvalue != '' ? 'hidden' : 'visible' }">
3. Use floating labels instead.
Floating labels will fill the entire width of the input. When the user touches/clicks inside the input, the label "floats" out of the way but remains visible for reference.
Similarly, a 'stacked' label will be placed above the input, but is fixed in place:
In addition to AndrWeisR's answer I couldn't get it working without the following (Ionic 4).
.item-input ion-label {
width: 150px;
flex: 0 0 150px;
}
Related
I want to disable this element for a few data classes:
<ion-item>
<ion-label position="stacked">Url</ion-label>
<ion-input type="text" value="{{data.url}}" [(ngModel)]="data.url" ></ion-input>
</ion-item>
I imagined it like this:
<ion-item [disabled]= if(this.ch === 'user' | 'todo' )>
<ion-label position="stacked">Url</ion-label>
<ion-input type="text" value="{{data.url}}" [(ngModel)]="data.url" ></ion-input>
</ion-item>
or
<ion-item [disabled]="*ngIf= this.ch === 'user' | 'todo'">
<ion-label position="stacked">Url</ion-label>
<ion-input type="text" value="{{data.url}}" [(ngModel)]="data.url" ></ion-input>
</ion-item>
ch is a variable which contains the name of the currently used dataclass -> for dataclass user and todo this item should be disabled
How can I achieve this?
P.S. If this is not possible in a similar way please let me know anyways.
you only need to put the condition in the disabled (no if, no ngIf)
<ion-item [disabled]="ch === 'user' || ch ==='todo'" >
Page.html
<form [formGroup]="myForm">
<ion-button [(ngModel)]="isActive"(click)="onClick()" >Add</ion-button>
<ion-item>
<ion-label position="floating">First Name</ion-label>
<ion-input type="text" [(ngModel)]="firstname" formControlName="firstname" ></ion-input>
</ion-item>
<ion-item class="item_country" >
<ion-label position="floating">Date Of Birth</ion-label>
<ion-datetime formControlName="date" [(ngModel)]="date" displayFormat="DD/MMM/YYYY">
</ion-datetime>
</ion-item>
<ion-item>
<ion-label position="floating">Passport number</ion-label>
<ion-input type="text" formControlName="passport" [(ngModel)]="passport" >
</ion-input>
</ion-item>
<div *ngIf="isActive">
<ion-item>
<ion-label position="floating">First Name</ion-label>
<ion-input type="text" [(ngModel)]="firstname1" formControlName="firstname1" >
</ion-input>
</ion-item>
<ion-item class="item_country" >
<ion-label position="floating">Date Of Birth</ion-label>
<ion-datetime formControlName="date1" [(ngModel)]="date1"displayFormat="DD/MMM/YYYY">
</ion-datetime>
</ion-item>
<ion-item>
<ion-label position="floating">Passport number</ion-label>
<ion-input type="text" formControlName="passport1" [(ngModel)]="passport1" >
</ion-input>
</ion-item>
</div>
page.ts
onClick(){
this.isActive = !this.isActive;
}
It will give formcontrol error like below:
I can't understand where am going wrong please help me. I want to show input fields when I click on a button and also hide when I click on it. but give error please help for this. Thank you for your help
You can't use both formControl and ngModel, just use one of them.
Read through the error screenshot you have posted. It has explanation.
If you want to use both formControlName and ngModel use [ngModeloptions]="{standalone:true}"
Remove ngModel from the input tag. You are using both ngModel (Template-driven based) as well as formControlName(Reactive form) on the input.
Or if you want to use it with ngModel then use [ngModelOptions]="{standalone: true}" with it. It is specified in your screenshot also.
Refer this: https://github.com/angular/angular/pull/10314#issuecomment-242218563
I want to bind 3 buttons to 3 different lists. I could use ion-segmentbut since I like the design over the segments I just do it with custom buttons. But now when I implement the *ngSwitchCase the lists are simply not displayed when I click on a button and I get this error Error: No value accessor for form control with unspecified name attribute
page.html
<ion-row [(ngModel)]="pre" [(ngModel)]="type" class="bg">
<ion-col col-4><ion-button value="own"</ion-button></ion-col>
<ion-col col-4><ion-button value="friends"</ion-button></ion-col>
<ion-col col-4><ion-button value="all" </ion-button></ion-col>
</ion-row>
<div [ngSwitch]="pre">
<ion-list *ngSwitchCase="'own'">
</ion-list>
<ion-list *ngSwitchCase="'friends'">
</ion-list>
<ion-list *ngSwitchCase="'all'">
</ion-list>
</div>
the issue here is that ion-row doesn't implement value accessor, which is required for using ngModel, you need to use an element that does implement value accessor.
for instance ion-segment
<ion-segment [(ngModel)]="type" [(ngModel)]="pre">
<ion-segment-button value="own">
Own
</ion-segment-button>
<ion-segment-button value="friends">
Friends
</ion-segment-button>
<ion-segment-button value="all">
All
</ion-segment-button>
</ion-segment>
it's weird to have two ngModels on one element, but you can if you'd like.
I am trying to put an ion-label that has the text $$$$$ on it for a price range. The range is inside an ion-menu. Here is the code I have:
<ion-item>
<ion-label>Price Range</ion-label>
<ion-range min="1" max="5" snaps="true" dualKnobs="true" pin="true" [(ngModel)]="priceRange" color="primary">
<ion-label range-left>$</ion-label>
<ion-label range-right>$$$$$</ion-label>
</ion-range>
</ion-item>
Which oddly displays this:
Even though I have $$$$$ in the html, it only displays $$.
For some reason, if I type in multiple extra $'s the display changes. For example:
<ion-item>
<ion-label>Price Range</ion-label>
<ion-range min="1" max="5" snaps="true" dualKnobs="true" pin="true" [(ngModel)]="priceRange" color="primary">
<ion-label range-left>$</ion-label>
<ion-label range-right>$$$$$$$$$$</ion-label>
</ion-range>
</ion-item>
Displays this:
Although this is the desired display I would like, it doesn't seem right to have to do what I did to achieve that.
How can I get the label to display $$$$$ in the proper way? I have tried setting the width, padding, and border properties to try and give the label more space but it does not affect anything.
Thank you for your time.
You can try this way. Declare any variable in your component file like below,
symbol : any = '$$$$$';
and then you can use it like below,
<ion-item>
<ion-label>Price Range</ion-label>
<ion-range min="1" max="5" snaps="true" dualKnobs="true" pin="true" [(ngModel)]="priceRange" color="primary">
<ion-label range-left>$</ion-label>
<ion-label range-right>{{symbol}}</ion-label>
</ion-range>
</ion-item>
Hi I already tried How to align ion-label to right, but this is not what I need. It is my first project in ionic 2 and java script, so i apologized if it is a stupid question.
I have a ion list:`
<ion-list >
<ion-item>
<ion-label floating>Company Name</ion-label>
<ion-input type="text" value="{{this.navParams.data.tenant.name}}"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Bot name</ion-label>
<ion-input type="text" value="{{this.navParams.data.tenant.name}}"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Bot Url</ion-label>
<ion-input type="text" value="{{this.navParams.data.tenant.name}}" text-left></ion-input>
<ion-label>mydomain.com</ion-label>
</ion-item>
</ion-list>
`
What I got is this:
What I want is:
".myDomain.com" should be a ion-label fixed the user can only change "Audi" to another.
You just need to set and order like the example
.label-right{
order: 2
}
<ion-list>
<ion-item>
<ion-label floating>Bot Url</ion-label>
<ion-input type="text" value="{{this.navParams.data.tenant.name}}" text-left></ion-input>
<ion-label class="label-right">mydomain.com</ion-label>
</ion-item>
</ion-list>