How to reset data on modal window Open? - angularjs

I have interesting situation Everytime when i open modal window i am reseting the value for below field, but if you select value 2 , 3 times and close modal with 'x' some time value retained in the select field. I am not sure why its happening any idea ?
main.html
<form name="addChallengeForm" id="addChallengeForm" novalidate ng-controller="challengesCtrl" class="border-box-sizing">
<div class="modalForm" disable-control-point="CHALLENGES_EDIT">
<div class="row" ng-show="editMode">
<div class="form-group col-md-12 fieldHeight">
<label for="originatingGroup" class="required col-md-4">Challenge Id:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="challangeId"
ng-model="challengesDTO.riskAssessmentChallengeKey" name="challangeId" readonly="readonly">
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12 fieldHeight">
<label for="originatingGroup" class="required col-md-4">Originating group:</label>
<div class="col-md-8">
<select
kendo-drop-down-list
data-text-field="'text'"
data-value-field="'id'" name="originatingGroup"
k-option-label="'Select'" ng-model-options="{updateOn: 'blur'}"
ng-model="challengesDTO.originatingGrpLkupCode"
k-data-source="challengeGroupOptions"
id="originatingGroup" required>
</select>
<p class="text-danger" ng-show="addChallengeForm.originatingGroup.$touched && addChallengeForm.originatingGroup.$error.required">Originating group is required</p>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12 fieldHeight">
<label for="challangeCreatedBy" class="col-md-4">Challenge created by:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="challangeCreatedBy"
ng-model="challengesDTO.initByWorker" name="challangeCreatedBy">
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label for="challangeDes" class="required col-md-4">Description of challenge:</label>
<div class="col-md-8">
<textarea rows="4" class="form-control"
name="challangeDes" id="challangeDes"
ng-model="challengesDTO.challengeDescription" required
placeholder="Description of challenge" ng-model-options="{updateOn: 'blur'}">
</textarea>
<p class="text-danger" ng-show="addChallengeForm.challangeDes.$touched && addChallengeForm.challangeDes.$error.required">Description of challenge is required</p>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label for="themesList" class="required col-md-4">Themes:</label>
<div class="col-md-8">
<select class="multiselect" kendo-multi-select="themes"
k-options="challengThemesOptions" data-text-field="'text'"
data-value-field="'id'" name="themesList"
ng-model="challengesDTO.themesKyList" required
k-data-source="challengThemesDataSource"
id="themesList"></select>
<p class="text-danger" ng-show="addChallengeForm.themesList.$touched && addChallengeForm.themesList.$error.required">Theme(s) is required</p>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12 fieldHeight">
<label for="ownerOrPreparer" class="col-md-4">RCSA Preparer
Responding to Challenge:</label>
<div class="col-md-8">
<input type="text" class="form-control" id="ownerOrPreparer"
ng-model="challengesDTO.challengeResponseWrk"
name="ownerOrPreparer" readonly="readonly" >
</div>
</div>
</div>
<div class="row" ng-show="editMode">
<div class="form-group col-md-12">
<label for="responseComment" class="col-md-4">RCSA Preparer Response:</label>
<div class="col-md-8">
<textarea rows="4" class="form-control"
name="responseComment" id="responseComment"
ng-model="challengesDTO.challengeResponseComment"
placeholder="RCSA Owner/Preparer Response">
</textarea>
</div>
</div>
</div>
<div class="row" ng-show="editMode">
<div class="form-group col-md-12 fieldHeight">
<label for="outcomeResolution" class="col-md-4">Outcome/Resolution:</label>
<div class="col-md-8">
<select
kendo-drop-down-list
data-text-field="'text'"
data-value-field="'id'" name="outcomeResolution"
k-option-label="'Select'" ng-change="mandatoryEscalation()"
ng-model="challengesDTO.challengeDesLkupCode"
k-data-source="challengOutComeOptions"
id="outcomeResolution" >
</select>
</div>
</div>
</div>
<div class="row" ng-if="editMode && showEscalation" disable-control-point="CHALLENGES_EDIT">
<div class="form-group col-md-12 fieldHeight">
<label for="requireEscalation" class="required col-md-4">Did the challenge
require escalation to be resolved?:</label>
<div class="col-md-8">
<select kendo-drop-down-list k-data-text-field="'text'"
k-option-label="'Select'" k-data-value-field="'id'"
k-options="escalationDataSource" name="requireEscalation"
ng-model="challengesDTO.esclRqrFlag" required
id="requireEscalation" ng-model-options="{updateOn: 'blur'}"></select>
<p class="text-danger" ng-show="addChallengeForm.requireEscalation.$touched && addChallengeForm.requireEscalation.$error.required">Challenge escalation is required</p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary pull-right" ng-disabled="addChallengeForm.$invalid" ng-click="submit()" require-control-point="CHALLENGES_ADD,CHALLENGES_EDIT">Save</button>
</div>
</form>
main.js
$scope.challengesDTO = {};
$scope.riskAssessmentDTO={
firstName: '',
lastName: '',
emailId: '' ,
nbkId: ''
};
$scope.$on('kendoRendered', function() {
rcsaAssessmentFactory.getThemeOptions().then(function(res){
$scope.challengThemesOptions.dataSource = new kendo.data.ObservableArray({data: res.data});
});
});
$scope.$on('addChallenge', function (s,id,opCheckList,checklistSessionKey){
$scope.addChallengeForm.originatingGroup.$setUntouched();
$scope.addChallengeForm.challangeDes.$setUntouched();
$scope.addChallengeForm.themesList.$setUntouched();
$scope.editMode = false;
$scope.clearFields = clearForm();
if($rootScope.user && $rootScope.user.customUserDetails){
$scope.challengesDTO.initByWorker= $rootScope.user.customUserDetails.workFullName;
}
rcsaAssessmentFactory.getAssessmentPreparerInfo(id).then(function(response){
$scope.riskAssessmentPreparer= response.data;
$scope.challengesDTO.challengeResponseWrkKey = $scope.riskAssessmentPreparer.rcsaPreparerWorkerKey;
$scope.challengesDTO.challengeResponseWrk = $scope.riskAssessmentPreparer.rcsaPreparerWorker;
});
$scope.riskAssessmentDTO.riskAssessmentKey = id;
$scope.challengesDTO.addChlngToChklst=opCheckList;
$scope.challengesDTO.riskAssessmentChecklistSessionKey=checklistSessionKey;
$scope.viewChallengeWin.open().center();
$scope.submit = function(){
rcsaAssessmentFactory.saveChallenge($scope.challengesDTO,id).then(function(){
$scope.viewChallengeWin.close();
$scope.$emit('refreshChallengeGrid');
$scope.addChallengeForm.$setPristine();
$scope.clearFields = clearForm();
});
};
});
var clearForm = function(){
$timeout(function () {
$scope.challengesDTO = {
themesKyList: null
};
});
$scope.challengeGroupOptions = kendoCustomDataSource.getDropDownDataSource('RA_ASES_CHLNG_GRP');
$scope.challengThemesDataSource = kendoCustomDataSource.getDropDownDataSource('RA_CHLNG_THEME');
$scope.challengOutComeOptions = kendoCustomDataSource.getDropDownDataSource('RA_CHLNG_OUTCOME');
$scope.riskAssessmentDTO={
firstName: '',
lastName: '',
emailId: '' ,
nbkId: ''
};
};

Related

Need help in implementing look up functionality using angular with spring boot

I am new to angular JS and I have a requirement where I need to implement the look up functionality on modal-pop up dialog box.It is similar to finding bank branch using IFSC code lookup.I should be able to serach for a bank using bank name or IFSC code or branch name and then select the bank branch.Please assist.Any demo videos implementing this functionality will help me.
I do have a working code for modal pop-up.But am unable to proceed further.Please let me know if I have to share the code of what has been done so far.
Thanks,
Prashanth
Here is my html code
<div class="container" xmlns="http://www.w3.org/1999/html">
<div class="offset-3"></div>
<form name="form" #f="ngForm" (ngSubmit)="f.form.valid && saveData()" novalidate class="feedback-form">
<div class="row">
<div class="col">
<label for="accession">Accession</label>
<input type="text"
id="accession"
class="form-control"
name="accession"
[(ngModel)]="model.accession"/>
</div>
<div class="col">
<label for="template">Template</label>
<input type="text"
id="template"
class="form-control"
name="template"
[(ngModel)]="model.template"/>
</div>
<div class="col">
<label for="user">User</label>
<input type="text"
id="user"
class="form-control"
name="user"
[(ngModel)]="model.user"/>
</div>
<div class="col">
<label for="count">Count</label>
<input type="text"
id="count"
class="form-control"
name="count"
[(ngModel)]="model.count"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="firstName">First Name</label>
<input type="text"
id="firstName"
class="form-control"
name="firstName"
placeholder="Your firstName" [(ngModel)]="model.firstName"
#firstname="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && firstname.invalid }"
required maxlength="40"/>
<div *ngIf="f.submitted && firstname.invalid" class="invalid-input">
<div *ngIf="firstname.errors?.required">
First Name is required
</div>
<div *ngIf="firstname.errors?.maxlength">
First Name can have a maximum of 40 characters
</div>
</div>
</div>
<div class="col">
<label for="doctorNumber">Doctor Number</label>
<input type="text"
id="doctorNumber"
class="form-control"
name="doctorNumber"
placeholder="Your doctorNumber" [(ngModel)]="model.doctorNumber"
(click)="open(content)"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="lastName">Last Name</label>
<input type="text"
id="lastName"
class="form-control"
name="lastName"
placeholder="Your lastName" [(ngModel)]="model.lastName"
#lastName="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && lastName.invalid }"
required maxlength="40"/>
<div *ngIf="f.submitted && lastName.invalid" class="invalid-input">
<div *ngIf="lastName.errors?.required">
Last Name is required
</div>
<div *ngIf="lastName.errors?.maxlength">
Last Name can have a maximum of 40 characters
</div>
</div>
</div>
<div class="col">
<label for="collectionCenter">Collection Center</label>
<input type="text"
id="collectionCenter"
class="form-control"
name="collectionCenter"
[(ngModel)]="model.collectionCenter" #collectionCenter="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && collectionCenter.invalid }"
required minlength="5" (keypress)="OnlyNumbersAllowed($event)"/>
<div *ngIf="f.submitted && collectionCenter.invalid" class="invalid-input">
<div *ngIf="collectionCenter.errors?.required">
Collection Center is required
</div>
<div *ngIf="collectionCenter.errors?.minlength">
Collection Center should be 5 digits in length
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="middleName">Middle Name</label>
<input type="text"
id="middleName"
class="form-control"
name="middleName"
placeholder="Your MiddleName" [(ngModel)]="model.middleName"/>
</div>
<div class="col">
<label for="state">State</label>
<input type="text"
id="state"
class="form-control"
name="state"
[(ngModel)]="model.state"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="sex">
Sex
</label>
<select id="sex" name="sex"
[(ngModel)]="model.sex" class="form-control">
<option *ngFor = "let sex of sexList" [ngValue]="sex.value">
{{sex.value}}
</option>
</select>
</div>
<div class="col">
<label for="billTo">Bill To</label>
<input type="text"
id="billTo"
class="form-control"
name="billTo"
[(ngModel)]="model.billTo" #billTo="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && billTo.invalid }"
minlength="3" maxlength="5"/>
<div *ngIf="f.submitted && billTo.invalid" class="invalid-input">
<div *ngIf="billTo.errors?.minlength">
Bill To should have a minimum of 3 characters
</div>
<div *ngIf="billTo.errors?.maxlength">
Bill To can have a maximum of 5 characters
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="dateOfBirth">Date Of Birth</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="dateOfBirth"
class="form-control"
name="dateOfBirth"
[(ngModel)]="model.dateOfBirth"
#dateOfBirth="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && dateOfBirth.invalid }"
required/>
<div *ngIf="f.submitted && dateOfBirth.invalid" class="invalid-input">
<div *ngIf="dateOfBirth.errors?.required">
Date Of Birth is required
</div>
</div>
</div>
<div class="col">
<label for="bioRefId">BioRef ID</label>
<input type="text"
id="bioRefId"
class="form-control"
name="bioRefId"
[(ngModel)]="model.bioRefId"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="receivedDate">Received Date</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="receivedDate"
class="form-control"
name="receivedDate"
[(ngModel)]="model.receivedDate"
#receivedDate="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && receivedDate.invalid }"
required/>
<div *ngIf="f.submitted && receivedDate.invalid" class="invalid-input">
<div *ngIf="receivedDate.errors?.required">
Received Date is required
</div>
</div>
</div>
<div class="col">
<label for="pid">PID</label>
<input type="text"
id="pid"
class="form-control"
name="pid"
[(ngModel)]="model.pid" #pid="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && pid.invalid }" maxlength="30"/>
<div *ngIf="f.submitted && pid.invalid" class="invalid-input">
<div *ngIf="pid.errors?.maxlength">
Patient Medical Record Number can have a maximum of 40 characters
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="receivedTime">Received Time</label>
<input type="text"
id="receivedTime"
class="form-control"
name="receivedTime"
[(ngModel)]="model.receivedTime"/>
</div>
<div class="col">
<label for="antiCoagulant">Anti-Coagulant</label>
<input type="text"
id="antiCoagulant"
class="form-control"
name="antiCoagulant"
[(ngModel)]="model.antiCoagulant"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="collectionDate">Collection Date</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="collectionDate"
class="form-control"
name="collectionDate"
[(ngModel)]="model.collectionDate" #collectionDate="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && collectionDate.invalid }"
required/>
<div *ngIf="f.submitted && collectionDate.invalid" class="invalid-input">
<div *ngIf="collectionDate.errors?.required">
Collection Date is required
</div>
</div>
</div>
<div class="col">
<label for="specimenType">
Specimen Type
</label>
<select id="specimenType" name="specimenType"
[(ngModel)]="model.specimenType" class="form-control">
<option *ngFor = "let spt of specimenTypeList" [ngValue]="spt.value">
{{spt.value}}
</option>
</select>
</div>
</div>
<div class="row">
<div class="col">
<label for="collectionTime">Collection Time</label>
<input type="text"
id="collectionTime"
class="form-control"
name="collectionTime"
[(ngModel)]="model.collectionTime"/>
</div>
<div class="col">
<label for="gptCode">GP Test Code</label>
<input type="text"
id="gptCode"
class="form-control"
name="gptCode"
[(ngModel)]="model.gptCode"/>
</div>
</div>
<div style="text-align:center">
<button type="submit" class="btn">
<span> Save</span>
</button>
</div>
</form>
<div class="offset-3"></div>
</div>
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Find Doctor</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form #f="ngForm">
<div class="row">
<div class="col">
<label for="lastname">Last Name</label>
<div class="input-group">
<input id="lastname" class="form-control" >
</div>
</div>
<div class="col">
<label for="upin">UPIN</label>
<div class="input-group">
<input id="upin" class="form-control" >
</div>
</div>
<div class="col">
<label for="code">Code</label>
<div class="input-group">
<input id="code" class="form-control" >
</div>
</div>
<div class="col">
<button type="submit" id="find" class="btn">
<span>Find</span>
</button>
</div>
</div>
<div class="row">
<div class="col">
<label for="firstname">First Name</label>
<div class="input-group">
<input id="firstname" class="form-control" >
</div>
</div>
<div class="col">
<label for="state">State</label>
<div class="input-group">
<input id="state" class="form-control" >
</div>
</div>
<div class="col">
<label for="extcode">Ext Code</label>
<div class="input-group">
<input id="extcode" class="form-control" >
</div>
</div>
<div class="col">
<button type="submit" id="Cancel" class="btn">
<span>Cancel</span>
</button>
</div>
</div>
</form>
</div>
</ng-template>
Here is my ts code
import { Component,OnInit } from '#angular/core';
import {HttpClient} from "#angular/common/http";
import {ModalDismissReasons, NgbModal} from '#ng-bootstrap/ng-bootstrap';
import { BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { Sex } from '../models/sex.model';
import { SpecimenType } from '../models/specimenType.model';
#Component({
selector: 'app-direct-client-trf',
templateUrl: './direct-client-trf.component.html',
styleUrls: ['./direct-client-trf.component.css']
})
export class DirectClientTRFComponent implements OnInit {
closeResult: string;
OnlyNumbersAllowed(event:any){
const charCode = (event.which)?event.which:event.keycode;
if(charCode > 31 && (charCode < 48 || charCode > 57)){
console.log('charCode is restricted'+charCode);
return false;
}
return true;
}
datePickerConfig: Partial<BsDatepickerConfig>;
specimenTypeList:SpecimenType[] = [
{id: 1,value: 'P'},
{id: 2,value: 'W'}
];
sexList:Sex[] = [
{id: 1,value: 'M:Male'},
{id: 2,value: 'F:Female'},
{id: 3,value: 'U:Unknown'}
];
model:DirectTrfViewModel = {
accession:'',
template:'',
user:'',
count:'',
firstName:'',
lastName:'',
middleName:'',
sex:'',
dateOfBirth:'',
receivedDate:'',
receivedTime:'',
collectionDate:'',
collectionTime:'',
doctorNumber:'',
collectionCenter:'',
state:'',
billTo:'',
bioRefId:'',
pid:'',
antiCoagulant:'',
specimenType:'',
gptCode:''
};
constructor(private http:HttpClient,private modalService: NgbModal){
this.datePickerConfig = Object.assign({},
{
containerClass : 'theme-dark-blue',
showWeekNumbers: false,
dateInputFormat: 'MM/DD/YYYY'
});
}
ngOnInit(){
}
saveData():void{
let url = 'http://localhost:8080/api/directtrfsubmit';
this.http.post(url,this.model).subscribe(
res => {
location.reload();
},
err => {
alert('Error in saving data');
}
);
}
open(content:any) {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}
export interface DirectTrfViewModel{
accession:string,
template:string,
user:string,
count:string,
firstName:string;
lastName:string;
middleName:string;
sex:string;
dateOfBirth:string;
receivedDate:string;
receivedTime:string;
collectionDate:string;
collectionTime:string;
doctorNumber:string;
collectionCenter:string;
state:string;
billTo:string;
bioRefId:string;
pid:string;
antiCoagulant:string;
specimenType:string;
gptCode:string;
}
With this the modal pop-up opens up and I need help in implementing the remaining functionality.

Unable to get the value using getAttribute method,and Javascript in selenium

the element marked i want to get the value to compare it with excel data
#FindBy(id="TAXEI")
//#FindBy(xpath="//*[#id='TAXEI']")
public WebElement taxesEIvalue;
public void verifyTaxesEIvalue() {
//jse.executeScript("arguments[0].setAttribute('type', '')",taxesEIvalue);
String value=taxesEIvalue.getAttribute("value");
System.out.println("the value is "+value);
}
I am facing problem to get the value in an application to compare it from excel,but unable to get value through Dom structure.The Html structure did't provide Value attribute
Here is the html code for the element unable to get the value that is in text box,i have compare with that value with the excel data using data driven
<div class="col-lg-6 col-md-6 col-sm-6">
<fieldset class="fsStyle">
<legend class="legendStyle">
<label class="control-label main">TAXES</label>
</legend>
<div class="wages">
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">EI</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXEI" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">QPIP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQPIP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">CPP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXCPP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">QPP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQPP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">Income Tax</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXIT" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">Quebec Tax</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQTax" disabled="disabled">
</div>
</div>
</div>
<a id="divExemptNamesIncome"></a>
<p class="form-control-static"><strong id="divExemptNamesIncome"></strong></p>
</div>
</fieldset>
</div>

Can not access ng-model values inside controller [angularJS]

When I try to access user.firstname value in controller, it gives the following error.
TypeError: Cannot read property 'firstname' of undefined
$scope.signUpCustomer = function(){
console.log("GGGGGGGGGGGGGGGGGGGGGGGGG ", $scope.user.firstname);
}
<form class="form-horizontal font-hp-simplified signUpUserForm row" role="form" ng-submit="signUpCustomer()" name ="signUpUserForm" ng-show="!userVendor">
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="firstname" class="col-md-12">First Name:</label>
<div class="col-md-12">
<input ng-model="user.firstname" type="text" class="form-control" name="firstname" required />
<span class="text-danger" ng-show="signUpUserForm.firstname.$invalid && signUpUserForm.firstname.$dirty ">First name is required</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="lastname" class="col-md-12">Last Name:</label>
<div class="col-md-12">
<input ng-model="user.lastname" type="text" class="form-control" name="lastname" required />
<span class="text-danger" ng-show="signUpUserForm.lastname.$invalid && signUpUserForm.lastname.$dirty ">Last name is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="email" class="col-md-12">Email:</label>
<div class="col-md-12">
<input ng-model="user.email" type="email" class="form-control" name="email" required />
<span class="text-danger" ng-show="signUpUserForm.email.$error.required && signUpUserForm.email.$dirty ">Email is required</span>
<span class="text-danger" ng-show="signUpUserForm.email.$error.email && signUpUserForm.email.$dirty ">Please enter valid email</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="password" class="col-md-12">Password:</label>
<div class="col-md-12">
<input ng-model="user.password" type="password" class="form-control" name="password" required />
<span class="text-danger" ng-show="signUpUserForm.password.$invalid && signUpUserForm.password.$dirty">Password is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="phone" class="col-md-12">Phone:</label>
<div class="col-md-12">
<input ng-model="user.phone" type="text" class="form-control" name="phone" required />
<span class="text-danger" ng-show="signUpUserForm.phone.$invalid && signUpUserForm.phone.$dirty">Phone is required</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="country" class="col-md-12">Country:</label>
<div class="col-md-12">
<select name="country" ng-model="user.country" type="text" class="form-control form-bg-white" required>
<!-- <option value="" disabled selected>Select Your Country</option> -->
<option value="" disabled selected></option>
<option ng-repeat="country in countries" value="{{country}}">{{country}}</option>
</select>
<span class="text-danger" ng-show="signUpUserForm.country.$invalid && signUpUserForm.country.$dirty">Country is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-12">
<!-- Button -->
<div class="form-group">
<div class="col-md-12">
<div class="icon-user-signup">
<div class="input-group-addon">
<i class="fa fa-user"></i>
</div>
<button id="btn-signup" class="btn btn-primary col-md-12">SIGN UP</button>
</div>
</div>
<!-- <div class="mrg-top-10 col-md-12 text-right">
<h4><a ng-click="go('/seller#/signup')" class="ven-link">
Become a vendor today
</a></h4>
</div>-->
</div>
</div>
</div>
<!-- <div class="col-md-12 control">
<div class="signup-border" >
Already have an account ?
<a ui-sref="loginUser" >
Sign In Here
</a>
</div>
</div> -->
</form>
You need to initialize the $scope.customer first in controller
$scope.user = {};

Recaptcha cant get response in angular after changing page

I have a problem with my angular application. I have a register page on my site. Normally when I get straight to the register page it works fine, after submitting the form is sent and user is registered. Problem appears when I for example load register page then go to login page and then again to register. In this case the form is not sent to server.
I tried to figure it out and even to repair by refreshing page after clicking register link but it didn't help.
I debug my application a little and found that it's recaptcha causing my problem. I use angular-recaptcha version 2.2.5; Tried to log the output of vcRecaptchaService.getResponse() but nothing showed in console.
Here is some code, where the problem may lay:
Request of form
$scope.registerRequest = (form) => {
$scope.$broadcast('show-errors-check-validity');
if (!form.$valid) {
return;
}
$scope.isLoading = true;
$scope.formData.reCaptcha = vcRecaptchaService.getResponse();
apiRequest.post('user/register', $scope.formData).success((response) => {
$scope.isLoading = false;
$scope.registered = true;
$scope.formData = {};
});
};
Routes:
app.config(['$routeProvider', ($routeProvider) => {
$routeProvider
.when('/auth/login', {
controller: 'authLogin',
label: 'Logowanie',
templateUrl: 'app/components/authLoginView.html',
access: ['UNAUTH']
})
.when('/auth/register/', {
controller: 'authRegister',
label: 'Rejestracja',
templateUrl: 'app/components/authRegisterView.html',
access: ['UNAUTH']
})
.when('/auth/register/confirm', {
controller: 'authRegister',
label: 'Potwierdzenie rejestracji',
templateUrl: 'app/components/authRegisterView.html',
access: ['UNAUTH']
})
.when('/auth/register/resend', {
controller: 'authRegister',
label: 'Rejestracja',
templateUrl: 'app/components/authRegisterView.html',
access: ['UNAUTH']
})
}]);
And some HTML:
<div ng-if="section == 'register'" class="container employer-container">
<form name="registerForm" class="form-horizontal col-sm-6 col-sm-offset-3" loader is-loading="isLoading">
<h4 class="employer-h4">Rejestracja</h4>
<p class="bg-success text-success col-xs-12" ng-show="registered">
Użytkownik został zarejestrowany. Na podany adres e-mail wysłaliśmy dalsze instrukcje.
</p>
<div ng-hide="registered">
<div class="form-group" show-errors>
<label for="email" class="col-md-3 control-label">E-mail:</label>
<div class="col-md-9">
<input type="text" class="form-control" id="email" placeholder="E-mail"
ng-model="formData.email" name="username"
ng-required="true">
</div>
</div>
<div class="form-group" show-errors>
<label for="password" class="col-md-3 control-label">Hasło:</label>
<div class="col-md-9">
<input type="password" class="form-control" id="password" placeholder="Hasło"
ng-model="formData.password" name="password" ng-minlength="5"
ng-required="true" equals="{{ formData.confirmPassword }}">
</div>
</div>
<div class="form-group" show-errors>
<label for="confirmPassword" class="col-md-3 control-label">Powtórz hasło:</label>
<div class="col-md-9">
<input type="password" class="form-control" id="confirmPassword" placeholder="Powtórz hasło"
ng-model="formData.confirmPassword" name="confirmPassword" ng-minlength="5"
ng-required="true" equals="{{ formData.password }}">
</div>
</div>
<div class="form-group" show-errors>
<label class="col-md-3 control-label" for="userType">Rodzaj konta:</label>
<div class="col-md-9">
<div class="btn-group" dropdown>
<button type="button" class="btn btn-default dropdown-toggle form-control"
id="userType" name="userType" dropdown-toggle ng-model="formData.userType"
ng-required="true">
{{ userTypes[formData.userType] || 'rodzaj konta' }} <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="(key, userType) in userTypes">
{{ ::userType }}
</li>
</ul>
</div>
</div>
</div>
<div class="form-group" show-errors>
<div class="col-md-3"></div>
<div class="col-md-9">
<input class="form-control" type="checkbox" id="acceptTerms" ng-model="formData.acceptedTerms" name="acceptTerms" ng-required="true">
<label class="control-label" style="text-align: left;" for="acceptTerms">Zgadzam się z  Regulaminem</label>
</div>
</div>
<div class="form-group" show-errors>
<div class="col-md-3"></div>
<div class="col-md-9">
<input class="form-control" type="checkbox" id="acceptTerms2" ng-model="formData.acceptedTerms2" name="acceptTerms2" ng-required="true">
<label class="control-label" style="text-align: left;" for="acceptTerms2">Wyrażam zgodę na przetwarzanie moich danych w celu realizacji usług w ramach Serwisu i akceptuję Politykę Prywatności..</label>
</div>
</div>
<div class="form-group" show-errors>
<div class="col-md-3"></div>
<div class="col-md-9">
<input class="form-control" type="checkbox" id="acceptTerms3" ng-model="formData.acceptedTerms3" name="acceptTerms3" ng-required="true">
<label class="control-label" style="text-align: left;" for="acceptTerms3">Wyrażam zgodę na przetwarzanie moich danych w celach marketingowych.</label>
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<div vc-recaptcha key="'key'"></div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
Zapomniane hasło |
Logowanie
</div>
<div class="col-md-3 text-right">
<button type="submit" class="btn btn-info" ng-click="registerRequest(registerForm)">Zarejestruj</button>
</div>
</div>
</div>
</form>
</div>
Problem could be seen here: http://pze2.biuro.netivo.pl/
Answering to one of questions about ['UNAUTH'] in my routes. It is for allowing only users who are not logged in to enter this page.
Thanks to Vinny I managed to solve the problem.
The problem lies as he said in reCaptcha.getResponse() not getting right widget.
For those who will have same problem I put the solution in my code:
Request:
$scope.registerRequest = (form) => {
$scope.$broadcast('show-errors-check-validity');
if (!form.$valid) {
return;
}
$scope.isLoading = true;
apiRequest.post('user/register', $scope.formData).success((response) => {
$scope.isLoading = false;
$scope.registered = true;
$scope.formData = {};
});
};
HTML:
<div ng-if="section == 'register'" class="container employer-container">
<form name="registerForm" class="form-horizontal col-sm-6 col-sm-offset-3" loader is-loading="isLoading">
<h4 class="employer-h4">Rejestracja</h4>
<p class="bg-success text-success col-xs-12" ng-show="registered">
Użytkownik został zarejestrowany. Na podany adres e-mail wysłaliśmy dalsze instrukcje.
</p>
<div ng-hide="registered">
...
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<div vc-recaptcha ng-model="formData.reCaptcha" key="'key'"></div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
Zapomniane hasło |
Logowanie
</div>
<div class="col-md-3 text-right">
<button type="submit" class="btn btn-info" ng-click="registerRequest(registerForm)">Zarejestruj</button>
</div>
</div>
</div>
</form>
</div>

bootstrap-ui modal with angular

I'm facing the following problem: When I try to instantiate a modal
angular.module('previewApp')
.controller('DienstleisterCtrl', function (dienstleisterRegObjService, staticDataService, $uibModal) {
var vm = this;
vm.dienstleisterTypen = staticDataService.getDienstleisterTypen();
vm.modRegObj = function (dienstleistertyp) {
dienstleisterRegObjService.vorselektiertesProdukt.typ = vm.dienstleisterTypen[dienstleistertyp];
var modalInstance = $uibModal.open({
templateUrl: 'scripts/angular/modals/templates/regform.html',
controller: 'RegFormCtrl as vm'
});
};
});
it throws in the modal controller
angular.module('previewApp')
.controller('RegFormCtrl', function (**$uibModalInstance**, dienstleisterRegObjService, staticDataService, fieldValidator) {
});
the error:
[$injector:unpr] Unknown provider: $uibModalInstanceProvider <-
$uibModalInstance <- RegFormCtrl
This is the modal:
It has two forms, one nested in the other.
<!-- Modal -->
<div class="portfolio-modal modal fade" id="portfolioModal1" tabindex="-1" role="dialog" aria-hidden="true" style="padding-right: 0px;">
<div class="modal-content">
<div class="close-modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<div class="form-horizontal" ng-form="regForm">
<fieldset>
<legend class="text-center">
<div class="panel formular-head">
<h3 class="formular-title">Registrieren</h3>
<p class="text-muted formular-description"></p>
</div>
</legend>
<div class="form-group">
<label class="col-md-4 control-label" for="organisation">Organisation</label>
<div class="col-md-6">
<input id="organisation" name="organisation" type="text" placeholder="z.B. Muster Catering GmbH" class="form-control input-md" ng-model="vm.regObj.organisation" ng-readonly="vm.orgReadOnly" ng-change="vm.checkValue('org')" ng-required="!vm.orgReadOnly">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="vorname">Vorname</label>
<div class="col-md-6">
<input id="vorname" name="vorname" type="text" placeholder="" class="form-control input-md" ng-model="vm.regObj.vorname" ng-readonly="vm.nameReadOnly" ng-change="vm.checkValue('name')" ng-required="!vm.nameReadOnly">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="nachname">Nachname</label>
<div class="col-md-6">
<input id="nachname" name="nachname" type="text" placeholder="" class="form-control input-md" ng-model="vm.regObj.nachname" ng-readonly="vm.nameReadOnly" ng-change="vm.checkValue('name')" ng-required="!vm.nameReadOnly">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-6">
<input id="email" name="email" type="text" placeholder="max#muster.ch" class="form-control input-md" ng-model="vm.regObj.mail" ng-required="true" ng-pattern="vm.getMailChecker();">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="natio">Nationalität</label>
<div class="col-md-6">
<select id="natio" name="nationalitaet" class="form-control" ng-model="vm.regObj.nationalitaet">
<option ng-value="vmnat" ng-repeat="vmnat in vm.nationalitaeten">{{vmnat}}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="sprache">Sprache</label>
<div class="col-md-6">
<select id="sprache" name="sprache" class="form-control" ng-model="vm.regObj.sprache">
<option ng-value="vmsprache" ng-repeat="vmsprache in vm.sprachen">{{vmsprache}}</option>
</select>
</div>
</div>
<div class="form-group produkt-katalog" ng-show="!vm.regObj.produkte.length == 0">
<label class="col-md-4 control-label produkt-label"></label>
<div class="col-md-6">
<div class="" ng-repeat="vmprod in vm.regObj.produkte track by $index">
<produkt-item produkt="vmprod"></produkt-item>
</div>
</div>
</div>
<div ng-form="produktForm">
<div class="formular-together panel shadowed">
<div class="form-group">
<label class="col-md-4 control-label" for="dienstleistertyp">Dienstleistung</label>
<div class="col-md-6">
<select id="dienstleistertyp" name="dienstleistertyp" class="form-control" ng-model="vm.vorselektiertesProdukt.typ" ng-required="vm.regObj.produkte.length == 0">
<option ng-value="vmtyp" ng-repeat="vmtyp in vm.typen">{{vmtyp}}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="produkt">Produkt</label>
<div class="col-md-6">
<input id="produkt" name="produkt" type="text" placeholder="z.B. Lautsprecher, Dekoration, Helfer, Stilrichtung" class="form-control input-md" ng-model="vm.vorselektiertesProdukt.produkt" ng-required="vm.regObj.produkte.length == 0 || vm.vorselektiertesProdukt.typ !== ''">
</div>
</div>
<div class="form-group">
<label class="col-md-4"></label>
<div class="col-md-6">
<button type="button" class="btn btn-default pull-right" name="submit" ng-click="vm.addProduct()" ng-disabled="produktForm.$invalid || vorselektiertesProdukt.produkt == ''">Hinzufügen</button>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-6">
<div class="pull-right">
<button id="abbrechen" name="abbrechen" class="btn btn-default">Abbrechen</button>
<button id="registrieren" name="registrieren" class="btn btn-default" ng-disabled="regForm.$invalid || regObj.produkte.length == 0" ng-click="vm.registrieren()">Registrieren</button>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Ende -->
In the app.js ui-bootstrap is declared, also in the index.html.
angular
.module('previewApp', [
'ngAnimate',
'ngSanitize',
'ngResource',
'ngTouch',
'ngMessages',
'ui.bootstrap',
'ngToast'
]);
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-animate/angular-animate.js"></script>
<script src="/bower_components/angular-resource/angular-resource.js"></script>
<script src="/bower_components/angular-messages/angular-messages.js"></script>
<script src="/bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="/bower_components/angular-touch/angular-touch.js"></script>
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/ngToast/dist/ngToast.js"></script>
This problem gives me headache, cause I know it's just a little fault, but in the last hours i tried nearly everything an nothing changed.
Help is very appreciated. I'll post an plunkr in the answers...
OK... I've no idea why or how it works but it does.
I did the following:
I changed "controller as" in creating modal plus removed named controllers from my index.html and replaced them by $scope.
I added in dienstleister.js, where the modal is beeing created, the modalinstance.result.then functions
Now there is no error anymore. If someone has an idea why it now works i would appreciate an explanation.
Thanks for your time guys.

Resources