How to push a form above the keyboard? - css

I have a form that gets visible when a button is clicked. I also have multiple input tags inside that form. When I type data on to the first input, it is visible but 2nd and 3rd input tags get hidden under the keyboard.
<div class="showmodal" *ngIf="formDisplay">
<div class="containdiv">
<ion-row class="milkColor">
<ion-label style="padding-left: 5%;">Add New Contact </ion-label>
<ion-icon class="iconPad" name="close" (click)="cancel()" > </ion-icon>
</ion-row>
<form #form="ngForm" (ngSubmit)="logForm(form)" novalidate>
<ion-row>
<ion-col>
<ion-label text-right> <b>Name :</b> </ion-label>
</ion-col>
<ion-col>
<ion-input [value]="name" name="name" [(ngModel)]="name" type="text" placeholder="Contact Name" required></ion-input>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-label text-right> <b>Occupation :</b> </ion-label>
</ion-col>
<ion-col>
<ion-input [value]="service" name="service" [(ngModel)]="service" type="text" placeholder="Occupation" required></ion-input>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-label text-right > <b>Contact No. :</b> </ion-label>
</ion-col>
<ion-col>
<ion-input [value]="number" name="number" [(ngModel)]="number" type="number" placeholder="Number" required></ion-input>
</ion-col>
</ion-row>
<ion-row >
<ion-col text-center>
<button [disabled]=!form.valid class="textLower" ion-button type="submit" value="Submit" >Submit</button>
</ion-col>
</ion-row>
</form>
</div>
</div>
and in my css
.showmodal {
position: fixed;
top: 0;
height: 100%;
width: 100%;
background: rgba(23, 22, 22, 0.2);
z-index: 10;
left: 0px;
}
.showmodal .containdiv {
background: white;
margin-top:52%;
min-height:30%;
overflow:auto;
margin: 150px 20px 0 17px;
}
I need all 3 inputs to be visible when that form arrives, and if I have more than 3 input tags, I should able to scroll the list of inputs
Can someone help me??

On the button (click) event where you set formDisplay to true to show the form, add scroll so the form content will go up a little and the inputs will show up higher on the screen and not hidden by the keyboard.
Something as the following:
HTML
<button ....(click)="displayForm()"...>Display Form</form>
Typescript
displayForm(){
...
this.displayForm=true;
window.scroll(0, 100); // or an other number of pixels enough to display
...
}

Related

Align to center two elements in a row in ionic v3

hello I have two ion toggle with their respective labels separated by columns in a row.
It looks like this:
How can I make both are in the center of the screen?
This is my code:
<ion-label class="titleFiltros" text-center>Filtrar por estado</ion-label>
<ion-list>
<ion-row>
<ion-col>
<ion-item no-lines>
<ion-label>Activa</ion-label>
<ion-toggle item-start [(ngModel)]="activa" (ionChange)="change()"></ion-toggle>
</ion-item>
</ion-col>
<ion-col>
<ion-item no-lines>
<ion-label>Anulada</ion-label>
<ion-toggle item-start [(ngModel)]="anulada" (ionChange)="change()"></ion-toggle>
</ion-item>
</ion-col>
</ion-row>
Appreciate your help.
Thanks.
Try this
<ion-label class="titleFiltros" text-center>Filtrar por estado</ion-label>
<ion-list>
<ion-row>
<ion-col class="ion-text-end">
<ion-item lines="none" style="float: right;">
Activa
<ion-toggle></ion-toggle>
</ion-item>
</ion-col>
<ion-col>
<ion-item lines="none">
Anulada
<ion-toggle></ion-toggle>
</ion-item>
</ion-col>
</ion-row>
</ion-list>
I found the solution and it works as I expected
Here I leave the code:
ion-item{
.input-wrapper{
flex:none;
margin-left: auto;
margin-right: auto;
}
ion-toggle{
margin-right:auto!important;
}
}

How to place the block button at the end of the page in ionic 5

Here i am trying to place the the button signin and other button at the end of the page using ionic and i am using the ionic css utilities but i am not sure why it is not changing
i want
here is my code
<ion-content>
<ion-grid size="12" size-sm="8" offset-sm="2" class="ion-text-center">
<ion-row>
<ion-col>
<ion-list>
<ion-item detail>
<ion-icon name="settings-outline">
</ion-icon>
Settings
</ion-item>
</ion-list>
</ion-col>
</ion-row>
<ion-row class="ion-align-self-end">
<ion-col>
<ion-button> Register Button</ion-button>
</ion-col>
</ion-row>
<ion-row class="ion-align-self-end">
<ion-col>
<ion-button expand="block" >Sign Button</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
Try this.
<ion-content>
<ion-grid style="height: 100%; display: grid;" size="12" size-sm="8" offset-sm="2" class="ion-text-center">
<ion-row>
<ion-col>
<ion-list>
<ion-item detail>
<ion-icon name="settings-outline">
</ion-icon>
Settings
</ion-item>
</ion-list>
</ion-col>
</ion-row>
<ion-row class="ion-align-self-end">
<ion-col><ion-button> Register Button</ion-button>
<ion-button expand="block" >Sign Button</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
You can use power of CSS flexbox to achieve that like so:
<ion-content>
<ion-grid size="12" size-sm="8" offset-sm="2" style="display: flex; flex-flow: column; height: 100%">
<ion-row style="flex-grow: 1">
<ion-col>
<ion-list>
<ion-item detail>
<ion-icon name="settings-outline">
</ion-icon>
Settings
</ion-item>
</ion-list>
</ion-col>
</ion-row>
<ion-row class="ion-align-self-center">
<ion-col>
<ion-button> Register Button</ion-button>
</ion-col>
</ion-row>
<ion-row class="ion-align-self-center">
<ion-col>
<ion-button expand="block">Sign Button</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
Basically you make your ion-grid element to display as flexbox in column and set height to occupy 100% of height.
Then you can apply "flex-grow: 1" to an ion-row to make it stretch across all available space. In your case you only need to give that to the first ion-row.
Other options could be playing with display: absolute and bottom: 0 in your CSS.

How to change ionic background color for an single page to two different colors

I´m trying to set the background color of a page in ionic project to two different colors, but this page have an element on it, so i´m having problems with it. The html code of the page is this:
<ion-content>
<div style="height: 100%; display: flex; align-items: center; justify-content: center; text-align: center;">
<ion-card>
<ion-card-header>
<ion-toolbar>
<ion-title>
<ion-item-divider>
<ion-label>
<img width="150" src = "./assets/images/logo.png">
</ion-label>
</ion-item-divider>
<ion-label>
<br/>Acceder
</ion-label>
</ion-title>
</ion-toolbar>
</ion-card-header>
<ion-card-content padding = "true">
<form #form="ngForm" method="post">
<ion-item>
<ion-input [(ngModel)] = "postData.username" type="text" name="username" placeholder="Usuario"></ion-input>
</ion-item>
<ion-item>
<ion-input [(ngModel)] = "postData.password" type="password" name="password" placeholder="Contraseña"></ion-input>
</ion-item>
<ion-item lines ='none'>
<a routerLink='/signup'>Create account</a>
</ion-item>
<ion-button expand="block" share = "round" color="primary" (click) ="loginAction()">Login</ion-button>
</form>
</ion-card-content>
</ion-card>
</div>
</ion-content>
Sorry for my english, is not my mother tongue

Chrome print aliasing with min-height ion-inputs

I'm using #media print styling to condense a bulky page of ion-inputs to reduce the page count by 15 pages.
Print to pdf (print preview and opening the saved pdf) looks good in Firefox v63,
but in Chrome v70 it produces aliasing or entire line absence when I set min-height, regardless of chrome page margins of None or Default. I have also seen it drop the id, description, subitem name, or the price line if they fall in the page break gap.
Is there a way to prevent Chrome from aliasing or dropping lines around its automatic page wraps/breaks?
--
Code:
#media print {
ion-item, .item-inner, .input-wrapper, ion-input, input {
min-height: 23px !important; // causes line aliasing
height: 24px !important;
max-height: 25px !important;
line-height: 26px !important;
}
}
<ion-card *ngFor="let eachCard of myCards">
<ion-row>
<ion-col col-2>
<ion-item>
<ion-input type="text" [(ngModel)]="eachCard.id"></ion-input>
</ion-item>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-11>
<ion-item>
<ion-input type="text" [(ngModel)]="eachCard.description1"></ion-input>
</ion-item>
<ion-item>
<ion-input type="text" [(ngModel)]="eachCard.description2></ion-input>
</ion-item>
<ion-item>
<ion-input type="text" [(ngModel)]="eachCard.description3"></ion-input>
</ion-item>
</ion-col>
</ion-row>
<div *ngFor="let eachSubitem of eachCard.subitems">
<ion-row>
<ion-col col-1></ion-col>
<ion-col col-5>
<ion-item>
<ion-input type="text" [(ngModel)]="eachSubitem.name"></ion-input>
</ion-item>
</ion-col>
<ion-col col-5>
<ion-item>
<ion-input type="text" [(ngModel)]="eachSubitem.altName"></ion-input>
</ion-item>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-1></ion-col>
<ion-col col-3>
<ion-item>
<ion-input type="number" [(ngModel)]="eachubitem.price"></ion-input>
</ion-item>
</ion-col>
<ion-col col-7>
<ion-item>
<ion-input type="text" [(ngModel)]="eachSubitem.unit"></ion-input>
</ion-item>
</ion-col>
</ion-row>
</div>
</ion-card>
Solved:
ion-item {
display: inline-block !important;
}

Ionic 3 Grid on Larger device is not working as expected (Hope I did it wrongly)

I'm using Ionic 3 flexbox grid system as shown below.This is a Modal `controller.
.html
<ion-content class="content">
<ion-grid no-padding>
<ion-row class="header">
</ion-row>
<ion-row padding class="details">
<ion-col>
<form [formGroup]="forgotPasswordForm" (submit)="goToNext()" novalidate>
<ion-item>
<ion-label>
<ion-icon name="person"></ion-icon>
</ion-label>
<ion-input type="text" placeholder="Distributor ID" formControlName="distributorId"></ion-input>
</ion-item>
<button ion-button block class="button-radius-25" type="submit"><span>Next <ion-icon name="arrow-round-forward"></ion-icon></span></button>
<ion-item no-lines>
<ion-label class="font-size-14" text-center>Not a member? Sign up now!</ion-label>
</ion-item>
</form>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
.scss
.content {
ion-grid {
height: 100%;
}
.header {
flex: 1;
}
.details {
flex: 3;
}
}
Mobile device - No issues
But on the desktop, it shows as below.
Q: It seems very bad on a larger device.How can I keep the same kind of ratio (I mean small sizes on components for Button and textbox) and centered the content on the larger device too? Hope you'll give the suggestions for this.
You can use col-sm-, col-md-... to change item size in different screen size:
<ion-row padding class="details">
<ion-col col-lg-6 col-md-6 col-12>
<form [formGroup]="forgotPasswordForm" (submit)="goToNext()" novalidate>
<ion-item>
<ion-label>
<ion-icon name="person"></ion-icon>
</ion-label>
<ion-input type="text" placeholder="Distributor ID" formControlName="distributorId"></ion-input>
</ion-item>
<button ion-button block class="button-radius-25" type="submit"><span>Next <ion-icon name="arrow-round-forward"></ion-icon></span></button>
<ion-item no-lines>
<ion-label class="font-size-14" text-center>Not a member? Sign up now!</ion-label>
</ion-item>
</form>
</ion-col>
</ion-row>
and to center item:
.details{
justify-content: center;
}
See more about ionic grid

Resources