I need to make the end slot of my list item take up less width so I can make the name in the first slot longer.
Currently it takes up around 50% of the width and is wasting space.
<ion-list *ngIf="!isLoading">
<ion-item *ngFor="let trail of trails" #defectReport (click)="onViewTrailDetails(trail)">
<fa-icon class="icon icon-center status-open-icon" *ngIf="trail.status === trailStatus.Open" slot="start" [icon]="['fas', 'check-circle']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-closed-icon" *ngIf="trail.status === trailStatus.Closed" slot="start" [icon]="['fas', 'times-circle']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-new-icon" *ngIf="trail.status === trailStatus.New" slot="start" [icon]="['fas', 'burn']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-under-construction-icon" *ngIf="trail.status === trailStatus.UnderConstruction" slot="start" [icon]="['fas', 'exclamation-triangle']" size="2x"></fa-icon>
<ion-label class="first-item-label">
<span><h2 class="heading">{{trail.name}}</h2></span>
<p class="label-text">{{trail.status}}</p>
</ion-label>
<ion-label slot="end" class="second-item-label">
<p class="sub-heading">{{trail.statusNotes}}</p>
<p class="label-text-small">{{trail.lastUpdated | timeAgo}}</p>
</ion-label>
</ion-item>
</ion-list>
I ended up using ion-note. It caused some formatting issues but resolved my problem.
https://ionicframework.com/docs/api/note
<ion-note slot="end" class="second-item-label" [ngClass]="{'margin-top-auto': !trail.statusNotes}">
<p class="sub-heading">{{trail.statusNotes}}</p>
<p class="label-text-small">{{trail.lastUpdated | timeAgo}}</p>
</ion-note>
ion-item is a flex container and ion-label has the style flex-grow: 1.
What I did is setting the first to flex-grow: 2, resulting in 2/3, 1/3 responsive proportions for labels.
In your case just add this to the CSS:
.first-item-label {
flex-grow: 2;
}
If you want the last label to have a fixed width, do this instead:
.second-item-label {
flex: 0 0 80px;
}
I recommend to use the following. Just change / reset the flex style of the label element, since it's a flex layout.
ion-label[slot='end'] {
flex: unset;
text-align: end;
}
The property text-align: end is optional and has nothing to do with the question. But in my opinion the right slot of an item should be right aligned. Especially input field.
You could use every element you want. But ion-label has some predefined styles which harmonize with the framework. And ion-note changes e.g. the font-size (in md style).
Update: This will be fixed in upcoming Ionic version (maybe Ionic 6). With this change flex: 1 is not longer set on slot="end".
Related
I've tried using
<ion-input formControlName="LPNumber" type="number">
LPNumber: ['', [Validators.required, Validators.minLength(20), Validators.maxLength(20)]]
but that doesn't seem to validate.... in chrome at least. Is there a better way to validate a 20 digit number in Ionic 4?
So by design if your input type is "number" the maxLength will be ignored.
There are many ways to workaround this. I used this approach (hacky a bit):
<ion-item>
<ion-label>MaxLength 4</ion-label>
<ion-input onKeyPress="if(this.value.length==4) return false;"
type="number"></ion-input>
</ion-item>
<ion-input formControlName="LPNumber" minlength="20" maxlength="20" type="number">
My way to do this is by:
<ion-input type="number" (ionChange)="onNumberChange($event)"></ion-input>
...
onNumberChange($event) {
// checks of number only. Doesn't allow + - . for in input
$event.target.value = $event.target.value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');
// checks for maxlength doesn't allow greater than specified length
$event.target.value = $event.target.value.length > 20 ? $event.target.value.substring(0, 20) : $event.target.value;
}
you can give type="text" then allow, but you give type="number" then not allow Validation, so you can give below like
page.html
<ion-item lines="none">
<ion-label position="stacked">Input Number</ion-label>
<ion-input formControlName="LPNumber" type="tel"></ion-input>
</ion-item>
<ion-item no-padding lines="none" class="validator-error"
*ngIf="property_form_step3.controls.LPNumber.hasError('required') && property_form_step3.controls.LPNumber.touched">
<p class="content">Please Enter Required Field!</p>
</ion-item>
<ion-item no-padding lines="none" class="validator-error"
*ngIf="property_form_step3.controls.LPNumber.hasError('maxlength') && property_form_step3.controls.LPNumber.touched">
<p class="content">Allow Only 20 Digits Number!</p>
</ion-item>
page.ts
LPNumber: [null, Validators.compose([Validators.maxLength(20), Validators.required])],
page.scss
.validator-error{
--background: transparent;
color: #d44848;
--min-height: 30px;
.content{
margin-bottom: 0px;
margin-top: 0px;
font-size: 12px;
}
}
On the top of the page, I’ve got a div for which background image has been set. I want to place the fab button on the bottom right edge of this div. Exactly like the following image. How can I do this?
Just use the edge attribute that comes along with fabs:
<ion-fab bottom right edge>
<button ion-fab><ion-icon name="camera"></ion-icon></button>
</ion-fab>
For this to work the div (or any tag) having the fab inside must have position set to relative, absolute or fixed to work, position: inherit may work too depending on parent positioning.
Hope this helps.
Thanks to #Garrett and #Gabriel, I got it working using the following markup and scss. It's important to place the FAB button inside the div to which we want to assign the background image so that we can use relative positioning:
<ion-content>
<div id="header">
<ion-fab bottom right edge>
<button ion-fab><ion-icon name="camera"></ion-icon></button>
</ion-fab>
</div>
</ion-content>
And the scss file:
#header {
background-image: url('../assets/images/anonymous.jpg')!important;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
height: 25vh;
}
ion-fab {
position: relative;
}
ion-fab[bottom][edge] {
bottom: -21vh;
}
.fab {
margin-right: 3vw;
}
Here is what I could get to work.
This works by creating a fab-container that is going to overlay the main container on this page. For this to work you need to know their heights. Then we make the fab-container z-index of 1 to be on top. Then we can use flex to make the fab be in the bottom right. Then we can add a margin-top half the size of the fab to the fab-container to have the fab hover halfway in-between. Lastly we can add margin-right to get the fab off the right side.
This may not be the best way to do it, since it requires knowing the height of your container, but it was the way that I would approach this task.
<ion-content>
<div class="container"></div>
<div class="fab-conatainer">
<ion-fab class="fab">
<button ion-fab>
<ion-icon name="camera"></ion-icon>
</button>
</ion-fab>
</div>
<div class="contacts-container">
<ion-list>
<ion-item>
<ion-input placeholder="Name"></ion-input>
</ion-item>
<ion-item>
<ion-input placeholder="Phone"></ion-input>
</ion-item>
<ion-item>
<ion-input placeholder="Email"></ion-input>
</ion-item>
</ion-list>
</div>
</ion-content>
CSS
.container {
width: 100%;
background: #333;
height: 500px;
}
.fab-conatainer {
display: flex;
justify-content: flex-end;
align-items: flex-end;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 500px;
z-index: 1;
margin-top: 28px;
}
.fab {
margin-right: 14px;
}
I am using Ionic 2 for building an app, I have created a login page which looks like this
Now When I try to type something in username fieild the keyboard pops out and the whole page scrolls upside like this
Now I am not able to see the text fields.
I have seen some solutions on google to stop scroll when keyboard come out.Even I have tried the same but then it behaves weird in landscape mode.
my login page code is.
<ion-content class="background">
<ion-card>
<ion-card-header>
<ion-icon name="ios-log-in"></ion-icon>
Login
</ion-card-header>
<ion-card-content>
<ion-list noline >
<ion-item>
<ion-label floating>Username</ion-label>
<ion-input class="inpt" type="text"></ion-input>
</ion-item>
<ion-item >
<ion-label floating>Password</ion-label>
<ion-input type="password"></ion-input>
</ion-item>
</ion-list>
<div padding>
<button ion-button block outline color="light">
<ion-icon name="ios-log-in"></ion-icon>
Sign In
</button><br />
<!-- <button ion-button block color="fb">
<ion-icon name="logo-facebook"></ion-icon>
Login with Facebook
</button> -->
</div>
<a href="">
Forgot Login Details?
<b>Get Help Signing IN</b>
</a>
</ion-card-content>
</ion-card>
<button ion-button block color="primary">Don't have an Account? Sign Up</button>
</ion-content>
This is my sass code:
page-login {
.background{
background-image:url('../assets/bg.jpg');
background-repeat: none;
}
.scroll-content{
align-content:center;
display:flex;
flex-direction:column;
}
ion-card.card{
box-shadow:none;
background:rgba(0,0,0,0.6);
border-radius:8px;
}
a, p, ion-card-header.card-header {
color:#fff;
}
.list > item-block:first-child{
border:medium none
}
.item{
margin-bottom:10px;
background:rgba(255,255,255,0.7);
border:medium none;
.text-input,{
color:green;
}
*:-moz-placeholder{
color:black !important;
}
*:-moz-input-placeholder{
color:black !important;
}
}
}
I have gone through some links which says that this is a bug in ionic beta version.
this link
Is there any standard solution on this issue ? because this functionality is common thing in all apps .
Bit confused to take a call to go with ionic or not .
I have a list of cards that I need to show them in 1 column in small devices and 2 columns in medium device and 3 columns in large devices
based on https://stackoverflow.com/a/36432126/2279488 and https://stackoverflow.com/a/36432126/2279488 I tried below codes but no success at the end.
1.
<ion-row responsive-sm>
<ion-col *ngFor="let card of cards" width-50>
<ion-card >
on small device it shows correctly, on large and medium it shows 2 cards only
2.
<ion-row responsive-sm>
<ion-col width-50>
<ion-card *ngFor="let card of cards">
on small device it shows correctly, on large and medium 1 column is shown and all cards are in the column
3.
<ion-row responsive-sm>
<ion-col>
<ion-card *ngFor="let card of cards">
on small device it shows correctly, on medium and large it shows only 1 column and cards are shown in that column
I found the solution, in case other people having same issue
I added wrap to my first code and it works.
<ion-row responsive-sm wrap>
<ion-col *ngFor="let card of cards" width-50>
<ion-card >
I added in my HTML below code and it working for me.
<ion-row class="categoryView">
<ion-col class="gridCol" width-40></ion-col>
<ion-col class="gridCol" width-40></ion-col>
</ion-row>
ion-col.gridCol.col {
height: 80px;
background: azure;
margin: 10px;
}
ion-row.categoryView.row {
height: 100px;
background: black;
}
I'm trying to align text in Html but it doesn't work and I do not know why. I'm using Ionic Framework.
My code is:
<ion-list>
<ion-item>
<b>Name</b> <p align="right"> {{paciente.name}}</p>
</ion-item>
....
</ion-list>
and it looks like this:
but I want all text int the same line, and I do not know how to get that.
See this demo: http://play.ionic.io/app/b477ea2f5623
In ionic items, if you write any text within span with item-note class then it will be aligned to right.This is built in class by ionic, your code will be like this :
<ion-item>
<b>Name</b> <span class="item-note"> {{paciente.name}}</span>
</ion-item>
See more tricks with ionic items provide by built in classes, see this Documentation
Add a css class as
.item {
position: absolute;
right: 0px;
width: 300px;
padding: 10px;
}
The p tag creates a paragraph on a new line, so you need an other element. You could use a span element which is floated right:
Html:
<ion-list>
<ion-item>
<b>Name</b> <span class="right"> {{paciente.name}}</span>
</ion-item>
....
</ion-list>
Css:
.right {
float: right;
}
Apply the ckass to all items you want to be on the right.