validation doesnt work in one instance - html

I have a dropdown in which when I select 'one' only then my input appears. That input is required field. What I want is when user select 'one' only then validation on the input works and hence on save button it shows error but if it selects other values or no value then on save it doesn't show validation error. My code is working correctly but only when I click on save button twice.If I click on the save once then it shows error even if I dont select anyone or select other one.
<form name="myForm" data-ng-submit="save(myForm.$valid)"novalidate="novalidate">
<div class="form-group">
<label class="col-md-6">Select:</label>
<select class="col-md-2" ng-model="val.value">
<option value="1" selected>one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<div ng-show="val.value=='1'">
<label class="col-md-3">one:</label>
<input type="number" class="col-md-4" ng-model="val.one" name="valOne" data-ng-class="{'has-error':myForm.valOne.$dirty && myForm.valOne.$invalid }" ng-required="val.value=='1'"/>
<div class="col-md-2" data-ng-messages="myForm.valOne.$error"
data-ng-show="myForm.valOne.$touched ||myForm.$submitted">
<div class="error-message" data-ng-message="required">Please enter Value
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-warning"><i class="fa fa-save"></i>
Save</button>
</form>
Please recommend something.

Related

show selected Drop down value in same page in angular4

I am working on Angular4 i want to show the selected dropdown value in the left side on the same page. i want the output like when selecting a packing type value and press add button the selected value can be moved to the right side portion.
actually, I am new in angular. can anyone help please its a big help form me
my Html Code is
<form #newForm="ngForm" (ngSubmit)="OnSubmit(newForm.value);newForm.reset()">
<div class="form-group">
<label>Packing Type</label>
<select class="form-control" >
<option value="0" disabled>Please Select Packing type</option>
<option *ngFor="let item of products" value={{item.ItemID}}>{{item.PackingtypeName}}</option>
</select>
</div>
for add button
<input type="button" value="Add Item" class="btn btn-success" (click)="addItems(newForm.value);newForm.reset()" />
</div>
this is my TS Component file
addItems(value: any) {
this.items = new IComboDetails(value.itemcode, value.itemdescription, value.PackingtypeName, value.quantity);
this.stockitems.push(this.items);
}
Here is working example
<select [(ngModel)]="myDropDown" (ngModelChange)="onChangeofmyOptions($event)">
<option value="one">One my value</option>
<option value="two">Two my value</option>
<option value="three">Three my value</option>
</select>
<input [hidden]="myDropDown !=='two'"type="text">
.ts
onChangeofOmyptions(newGov) {
console.log(newGov);
}
in your case
<select class="form-control" (ngModelChange)="onChangeofmyOptions($event)" >
<option value="0" disabled>Please Select Packing type</option>
<option *ngFor="let item of products" value={{item.ItemID}}>{{item.PackingtypeName}}</option>
</select>
onChangeofOptions(newGov) {
console.log(newGov);
this.myDropDown=newGov;
}
get value to right side
<input type="text" value={{myDropDown}}>
for binding
this.myDropDown=newGov;

Angular 6 and bootstrap 4: date picker

I have a form which contain a date picker / calender, email, city name and hotel name, I want a user to select a date and enter other fields and submit the data.
This is what I have.
HTML:
<form [formGroup]="angForm" class="form-element">
<div class="form-group">
<label for="dateOfBirth">Date of Birth</label>
<input id="dateOfBirth" name="dateOfBirth" [(ngModel)]="dateOfBirth" type="text" bsDatepicker class="form-control" />
</div>
<div class="form-group form-element_email">
<input type="email" class="form-control info" placeholder="Email" formControlName="email" #email (ngModelChange)="onChange($event)">
</div>
<div *ngIf="angForm.controls['email'].invalid && (angForm.controls['email'].dirty || angForm.controls['email'].touched)"
class="alert alert-danger">
<div *ngIf="angForm.controls['email'].errors.required">
Email is required.
</div>
</div>
<div class="input-group mb-3 form-element_city">
<select class="custom-select" id="inputGroupSelect01" #cityName>
<option selected *ngFor="let city of cities" [ngValue]="city.name">{{city.name}}</option>
</select>
</div>
<div class="input-group mb-3 form-element_hotel">
<select class="custom-select" id="inputGroupSelect01" #hotelName>
<option selected *ngFor="let hotel of hotels" [ngValue]="hotel.name">{{hotel.name}}</option>
</select>
</div>
<div class="form-group">
<button type="submit" (click)="addReview(email.value, cityName.value , hotelName.value)" class="btn btn-primary btn-block form-element_btn"
[disabled]="!validEmail">Book</button>
</div>
</form>
This dispalys the following result: wrong one
Instead of that input with date picker , I just want the full calender to be display on the left side ,
Here is what I want . Good one
I tried many solution online I could not be able to solve my problem,
What do I need to change in my code to get the result I want? please Am newbie though, thanks
You can actually provide placement in the element which uses bdDatepicker directive.
Just set this placement property to left value.
Here is example in documentation.
https://valor-software.com/ngx-bootstrap/#/datepicker#placement

Ensure that a user selects a value in the dropdown on submission when using Odoo html form builder

I have a dropdown in my form which was generated by the html form builder:
<select class="form-control">
<option value="" selected="1" disabled="1">Select option</option>
<option value="course 1">course 1</option>
<option value="course 2">course 2</option>
<option value="course 3">course 3</option>
</select>
Is there a simple way to ensure that the user selects a value in the dropdown before submitting the form? If he has not selected anything, then display an error message.
Also, I have an input field:
<div class="form-group field-x_street_name_1">
<label for="x_street_name_1" class="col-sm-2 col-form-label col-form-label-lg">Street 1 <span style="color:red;">*</span></label>
<div class="col-sm-10">
<input type="text" name="x_street_name_1" t-att-value="x_street_name_1" id="x_street_name_1" class="form-control form-control-lg" placeholder="e.g. John Lane" required="required" t-att-readonly="'readonly' if only_passwords else None" t-att-autofocus="'autofocus' if login and not only_passwords else None"/>
</div>
</div>
I want to ensure the user enters only between 10 to 30 uppercase, lowercase alphabets. I would ensure that using html pattern simply. But it does not seem to work.

required not working for dropdown in html

I am facing this issue with required tag. I want to make the quality field as mandatory without the valid option selected from the list the update billing button should not be enabled. Am I missing anything in the code? Please check the else condition part
I will be thankful for the help here.
else
{
<div class="form-horizontal" ng-class="{'has-error':Edit.Quality.$invalid &&
Edit.Quality.$dirty}">
<div class="form-group">
<label class="control-label col-lg-2 pull-left">Quality<span class="Imp">*</span></label>
<div class="col-lg-8">
<select id="Quality" name="Quality" class="form-control" style="width:170px" ng-model="vm.EditRef_UI.Quality" tooltip="Quality is required"
tooltip-placement="top" tooltip-trigger="mouseenter" required>
<option selected disabled value="">(Select a Timeline)</option>
<option value="Satisfactory">Satisfactory</option>
<option value="NotSatisfactory">Not Satisfactory</option>
</select>
</div>
</div>
</div>
}
button code:
<button type="button" class="btn btn-primary" data-dismiss="modal" data-ng-click="vm.Edit()" ng-disabled="Edit.$invalid" id="ticketEditbtn">Update Billing</button>
Angular does the string bindings as this article suggested, thus satisfying the condition by the value being passed. This prevents the required from firing, thinking that there was value in the selected option.
you can use loke this :
<select id="Quality" name="Quality" class="form-control" style="width:170px" ng-model="vm.EditRef_OCBUI.Quality" tooltip="Quality is required"
tooltip-placement="top" tooltip-trigger="mouseenter" required="required">
i wil be work

assign a form element to more than one form

I have this small form with two submit buttons, on clicking each button I want form data to be sent to different PHP file. But, both submit buttons are sending the form data to the default PHP file specified in the action attribute of the form tag. Is there a way to send the form data to different files with different buttons. I made an unsuccessful attempt to do so by redefining the action attribute in the second submit button
<div class="dropdown dropdown-dark">
<select name="promoteyearselect1" id="promoteyearselect1" class="dropdown-select" onfocus="showhidephdmenu()" form="promotionform" required>
<option value="">Select an option</option>
<div id="yearselect1">
<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">5th</option>
</div>
</option>
</select>
</div>
<select name="promotesemselect1" id="promotesemselect1" class="dropdown-select" form="promotionform" required>
<option value="">Select an option</option>
<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">5th</option>
<option value="6">6th</option>
<option value="7">7th</option>
<option value="8">8th</option>
<option value="9">9th</option>
<option value="10">10th</option>
</select>
<form id="promotionform" action="promotestudents.php" method="POST">
<div style=" position:relative; margin-top:10px; padding-left:44%;">
<input type="submit" value="Promoted" class="button black" />
<input type="submit" value="Passed Out" class="button black" form="promotionform" action="alumni.php"/>
</div>
</form>
Two separate forms wont work, the page will submit in between. You need Ajax to send the data behind the scene without refreshing the page
finally did it with the help of this code.
source: http://blog.theonlytutorials.com/multiple-submit-button-in-a-single-form-with-php/
<?php
if(isset($_POST['submit1']))
{
echo "You hit the button 1";
}
if(isset($_POST['submit2']))
{
echo "You hit the button 2";
}
?>
<html>
<head><title>Multiple Submit button Solved with PHP!</title></head>
<body>
<form action="" method="post">
<h2> Hit the Submit Button</h2>
<input type="submit" name="submit1" value="btn1" />
<input type="submit" name="submit2" value="btn2" />
</form>
</body>
just use jQuery:
$(document).ready(function(){
$('#button1').click(function(){
$('#yourForm').attr("action","phpFile1.php");
$('#yourForm').submit();
});
$('#button2').click(function(){
$('#yourForm').attr("action","phpFile2.php");
$('#yourForm').submit();
});
});