How to get value <span class="ng-binding">TestFolder</span> result should be TestFolder - protractor

<div class="file-folder-breadcrumbs-child-panel ng-hide" ng-show="isExpanded(root.full)">
<!-- ngRepeat: child in root.nodes -->
<div ng-repeat="child in root.nodes" class="ui-state-default filedrop file-folder-breadcrumbs-item-child ng-scope" ng-click="navigateToChild($event, child, root)">
<span class="ng-binding">TestFolder</span>
</div>
<!-- end ngRepeat: child in root.nodes -->
</div>
I am not able to get TestFolder by using:
const myDiv=element.all(by.repeater('item in currentPathNodes track by $index')).filter(item => item.element(by.className('ui-state-default btn btn-toolbar ng-scope'))).filter(item => item.element(by.className('file-folder-breadcrumbs-item-part name'))).filter(item => item.element(by.className('ng-binding')).getText().then(label => label === fileName));
console.log(myDiv);
return folderName;
please help

Related

storing form and rout

I have problem on storing form . All my efforts will be damaged if I could not solve it.
The GET method is not supported for this route. Supported methods: POST.
what happen now :
1.When I press on register which is linked to this rout :
Route::POST('/jobs/apply/{id}/', [JobseekerController::class,'applyforjob'])->name('aplpy1');
there will be two scenarios:
if the user has cv it will register the user directly.(works)
if the user has not cv it will direct the user to create cv view .(works)
This is a part of create cv view :
<form method="POST" action="{{route('storing')}}" enctype=multipart/form-data>
#csrf
<input type="hidden" name=job_id value= {{$s}}>
#if (count($errors) > 0)
<div class="alert alert-danger alert-dismissible fade show">
<strong>Opps!</strong> Something went wrong, please check below errors.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
<div class="card-body">
<div class="container">
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="accordion" class="checkout">
<div class="panel checkout-step">
<div> <span class="checkout-step-number">1</span>
<h4 class="checkout-step-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" > Personal Information</a></h4>
</div>
<div id="collapseOne" class="collapse in">
<div class="checkout-step-body">
<div class="row mt-3 pr-3">
<div class="col-6 ">
<strong>Full Name:</strong>
{!! Form::text('FName', null, array('placeholder' => 'Full Name','class' =>
'form-control pb-4')) !!}
</div>
<div class="col-6">
<div class="row mt-3 mr-2">
<strong>Nationality:</strong>
<select name="Nationality" class="custom-select">
#foreach(\App\Models\Nationality::all() as $nation)
<option value="{{$nation->name}}">{{$nation->name}}</option>
#endforeach
</select>
</div>
<div class="form-group ">
<button type="submit" name="submit" class="btn btn-primary ">{{ __('APPLAY') }}</button
</div>
<input type="hidden" name=job_id value= {{$s}}>
</form>
2.Now Here is the problem:
If I fill all the fields on the form correctly and click apply it works , but if there is missing field or anything not filled as it should be and then click apply , although there is validation on controller it does not work it gives this error:
The GET method is not supported for this route. Supported methods: POST.
Although I am using Post this my rout that I use to store the form
Route::POST('/jobsapply', [JobseekerController::class,'store'])->name('storing');
This my controller for storing:
public function store(Request $request )
{
$this->validate($request, [
'FName' => 'required|alpha|regex:/^([^"!\*\\]*)$/',
'Nationality' => 'required',
]);
$input = $request->all();
$input = $request->except(['_token']);
$cv = new cv();
if ($this->cvsave($cv, $request )) {
$data = Job::all();
$cv = auth()->user()->cv;
return view ('show',compact('cv' ,'data'))->with('success', 'CV created successfully.');
}
$data = Job::all();
return view('show')->with('Failed!', 'error');
}
public function cvsave(cv $cv, Request $request)
{
$cv->FName = $request->FName;
$cv->Nationality = $request->Nationality;
if ($cv->save()) {
$application = new JobApplication;
$id=$request->job_id;
$jobs = Job::find($id)->get();
$application->job_id =$request->job_id;
$user = User::find(auth()->user()->id);
$application->user_id = auth()->user()->id;
$cv = auth()->user()->cv;
$i= $cv->id;
$application->cv_id = $i;
$application->save();
\Session::flash('success', 'Thank you for applying! Wait for the company to respond.!');
return true;
}
return false;
}
I could not know the reason, I have read lots of stuff but still the same error

how to define an entity inside the function symfony 5

for exemple this is my function :
/**
* #Route("/companyProfile/{id_Adresse}/{id_Employes}/{id_Contact}", name="company_profile")
* #ParamConverter("Adresse", options={"mapping": {"id_Adresse" : "id"}})
* #ParamConverter("Employes", options={"mapping": {"id_Employes" : "id"}})
* #ParamConverter("Contact", options={"mapping": {"id_Contact" : "id"}})
*/
public function index(Adresse $adresse , Employes $employes , Contact $contact,ContactRepository $contactrepository, EmployesRepository $employesrepository , AdresseRepository $adresserepository ): Response
{
$contactform=$this->createForm(ContactType::class, $Contact);
$employesform=$this->createForm(EmployesType::class, $Employes);
$adresseform=$this->createForm(AdresseType::class, $Adresse);
return $this->render('companyProfile.html.twig', [
'Contact' => $contactrepository->findAll(),
'Employes' => $employesrepository->findAll(),
'Adresse' => $adresserepository->findAll(),
'contactform'=>$contactform->createView(),
'employesform'=>$employesform->createView(),
'adresseform'=>$adresseform->createView()
]);
}
as you can see i declare all my entity in the parameter but i need to add all there ids in the route and that's not what i need , i just want my route to be like this :
/*
*#Route ("/companyProfile", name="company_profile")
*/
thanks in advance for all your answer
The param converter goal is the retrieve an entity from a route parameter. My guess is that you want to get all this entities but not with their ids in the route.
To do so, you will need to get the repository for each of your entity and then get them here. There is a question still : how do you know which entity do you want?
Here is an exemple of your action
/**
* #Route("/companyProfile", name="company_profile")
*/
public function index(ContactRepository $contactRepository, EmployesRepository $employesRepository , AdresseRepository $adresseRepository): Response
{
$contactform = $this->createForm(ContactType::class, $contactRepository->find($contactId);
$employesform = $this->createForm(EmployesType::class, $employesRepository->find($employesId);
$adresseform = $this->createForm(AdresseType::class, $adresseRepository->find($adresseId);
return $this->render('companyProfile.html.twig', [
'Contact' => $contactrepository->findAll(),
'Employes' => $employesrepository->findAll(),
'Adresse' => $adresserepository->findAll(),
'contactform'=>$contactform->createView(),
'employesform'=>$employesform->createView(),
'adresseform'=>$adresseform->createView()
]);
}
You still need a way to get all this new ids variables, but I can't help you more with the given informations.
i tried a different way to display them but when i want to edit for exemple contact , it dosen't work and they show me this error:
An exception has been thrown during the rendering of a template ("Notice: Undefined index: Contact").
here's a screenshot:
enter image description here
and here's my code :
/**
* #Route("/companyProfile/", name="company_profile")
*/
public function index(): Response
{
$Contact = $this->getDoctrine()
->getRepository(Contact::class)
->findAll();
$Employes = $this->getDoctrine()
->getRepository(Employes::class)
->findAll();
$Adresse = $this->getDoctrine()
->getRepository(Adresse::class)
->findAll();
return $this->render('companyProfile.html.twig', [
'Contact' => $Contact,
'Employes' => $Employes,
'Adresse' => $Adresse,
]);
}
this is the edit function:
/**
* #Route("/UpdateContact/{id}",name="editcontact")
*/
public function EditContact(Contact $contact , Request $request ,ManagerRegistry $manager)
{
$contactform=$this->createForm(ContactType::class, $contact);
$contactform->handleRequest($request);
if($contactform->isSubmitted() && $contactform->isValid())
{
$manager = $this->getDoctrine()->getManager();
$manager->persist($contact);
$manager->flush();
return $this->redirectToRoute('company_profile');
}
return $this->render('companyProfile.html.twig', [
'contactform'=>$contactform->createView()
]);
}
and last my twig :
<div class="boxed-list margin-bottom-60">
<div class="boxed-list-headline">
<h3><i class="icon-material-outline-business-center"></i> les contactes d'entreprise</h3>
</div>
</br>
{% for Contact in Contact %}
<div class="listings-container compact-list-layout">
<ul class="list-group">
<li class="list-group-item">
<h3>Contact</h3>
</br></br>
<div class="container pt-3">
<h5>Responsable:</h5>
<p>{{Contact.responsable}}</p>
<h5>N° de tele:</h5>
<p>{{Contact.telephone}}</p>
<h5>Addresse email:</h5>
<p>{{Contact.email}}</p>
<h5>Note:</h5>
<p>{{Contact.note}}</p>
<div class="centered-button margin-top-35">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Modifier
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- Form -->
<form method="post" id="add-note">
<div class="form-group">
<label for="nom">Responsable:</label>
<input type="text" class="form-control" placeholder="{{Contact.responsable}}" id="nom">
</div>
<div class="form-group">
<label for="tele">N° de tele:</label>
<input type="text" class="form-control" placeholder="{{Contact.telephone}}" id="telephone">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" placeholder="{{Contact.email}}" id="email">
</div>
<label for="note">Note:</label>
<textarea name="textarea" cols="10" placeholder="{{Contact.note}}" class="with-border"></textarea>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button><i class="icon-material-outline-arrow-right-alt"></i>
</div>
</div>
</div>
</div>

How to get span value which has ng-bulding class?

I can get value when I tried this on console using:
$x("//*[#class='file-folder-breadcrumbs-item-part name']")[1].innerText;
or
document.querySelector("[ng-if='currentPathNodes.length']").innerText;
but not able to convert in this JavaScript code in Protractor code.
Below is HTML
<div class="file-folder-breadcrumbs-child-panel ng-hide" ng-shenter image ow="isExpanded(root.full)">
<!-- ngRepeat: child in root.nodes -->
<div ng-repeat="child in root.nodes" class="ui-state-default filedrop file-folder-breadcrumbs-item-child ng-scope" ng-click="navigateToChild($event, child, root)">
<span class="ng-binding">TestFolder</span>
</div>
<!-- end ngRepeat: child in root.nodes -->
</div>
I think this is what you are looking for:
const breadcrumbPart = element.all(by.css('.file-folder-breadcrumbs-item-part.name').first();
const myText = await breadcrumbPart.getText();
// console.log(myText);
expect(myText).toEqual('something');
Or synchronous solution:
const breadcrumbPart = element.all(by.css('.file-folder-breadcrumbs-item-part.name').first();
breadcrumbPart.getText().then(myText => {
// console.log(myText);
expect(myText).toEqual('something');
});

Why validation is not working?

corporate.html
<form #f="ngForm" name="corporateProfileForm" ng-submit="corporateFrmSave(objDS, objDSCurrency)" novalidate="">
<div class="row form-group">
<div class="col-md-12" >
<input type="text" *ngIf="formData" [(ngModel)]="formData.Corporate_Id" id="corpid" title="Corporate ID" tab-index="1" name="corpid" maxlength="20" #corpid="ngModel" required/>
<label for="corp"><b>Corporate ID</b></label>
<div *ngIf="corpid.invalid && (corpid.dirty || corpid.touched)" class="alert alert-danger">
<div *ngIf="corpid.errors.required">
Name is required.
</div>
<div *ngIf="ncorpidame.errors.minlength">
Name must be at least 4 characters long.
</div>
<div *ngIf="corpid.errors.forbiddenName">
Name cannot be Bob.
</div>
</div>
</div>
</div>
</form>
Iam getting error message as
ERROR TypeError: Cannot read property 'invalid' of undefined
Make sure you define your variable with this structure:
TS file
export class ContactComponent implements OnInit {
myform: any;
corpid: FormControl;
constructor() {
}
ngOnInit() {
this.createFormControls();
this.createForm();
}
createFormControls() {
this.corpid= new FormControl('', Validators.required);
}
createForm() {
this.myform = new FormGroup({
corpid: this.corpid,
});
}
HTML file
<div class="md-form form-sm form-group"
[ngClass]="{
'invalid': corpid.invalid && (corpid.dirty || corpid.touched),
'valid': corpid.valid && (corpid.dirty || corpid.touched)
}">
<i class="fa fa-user prefix"></i>
<input
type="text" id="corpid" class="form-control"
required
[formControlName]="'corpid'">
<label for="corpid" class="">Your corpid</label>
</div>
<div class="form-control-feedback"
*ngIf="corpid.errors && (corpid.dirty || corpid.touched)">
<p *ngIf="corpid.errors.required">corpid is required</p>
</div>
It's hard to tell because issue is not in your HTML snipped but in .ts file.
I hope my Code will be helpfull
The issue is with the *ngIf, so when that condition is checked, Angular renders the rest of the template, and while the small fraction of time while *ngIf is being evaluated, your template reference variable corpid does not exist, so it will throw an error when trying to check the validation intially.
Wrap the input field with the validation div's inside the *ngIf instead of applying it only on the input field.
<div class="row form-group" *ngIf="formData">
<input [(ngModel)]="formData.Corporate_Id" id="corpid" ... >
<!-- more code here... -->
</div>
DEMO

angular2 formArray conditional validation

I'm trying to impose validation based on a change of one field onto another field inside a formGroup which is inside a FormArray of multiple instances of this group. I'm using mydatepicker on one of the fields. For example, when the date is changed, I then want the Reason for change field in that group only to be validated to check to make sure the first option (value of 0) is not selected. I have 2 problems with this:
When I change the date, the Reason for change field does not get checked for validity right away. It only happens AFTER I change the value of the field to 1 and then to 0. It's default is set to 0 and it should immediately pick this up when I change the date.
When it does finally realize the form is invalid, it does it for ALL the update buttons rather than just the one in the FormGroup whose Date field I have changed.
ts file code:
subscribeDateChange(formGroup){
(<any>this.rfcActionTasksForm).controls.tasks.controls[0].controls['DueDate'];
const tasks = formGroup;
const changes$ = tasks.controls['DueDate'].valueChanges;
changes$.subscribe(dd => {
var arrayControl = this.rfcActionTasksForm.get('tasks') as FormArray;
var item = arrayControl.at(1);
console.log(item);
if(tasks.value['ReasonForChangeId'] == '0'){
tasks.controls['ReasonForChangeId'].setValidators(Validators.pattern(/([1-9])/));
}
});
}
ngOnInit() {
this.rfcActionTasksForm = this._fb.group({
tasks: this._fb.array([this.buildTask()])
});
}
buildTask(): FormGroup {
return this._fb.group({
Id: '',
Action: ['', Validators.required],
Step: '',
AssignedToId: ['', Validators.required],
AssignedToColour: '',
DueDate: ['', Validators.required],
ReasonForChangeId: '',
OriginalDueDate: '',
Completed: '',
OverDue: ''
},{
validator: (formGroup: FormGroup) => {
//return this.validateDays(formGroup);
//console.log(formGroup.controls['DueDate']);
//this.subscribeDateChange(formGroup.controls['DueDate'], formGroup.controls['ReasonForChangeId']);
return this.subscribeDateChange(formGroup);
}
});
}
html:
<form class="multi-col implementation" *ngIf="rfc.Plan [formGroup]="rfcActionTasksForm">
<div class="task-item" formArrayName="tasks" *ngFor="let task of tasks.controls; let i = index">
<div [formGroupName]="i">
<div class="row header-row">
<div class="col-md-12">
<h5 class="no-margin">Step {{i + 1}}</h5>
<input
[style.display]="'none'"
formControlName="Step">
<input
[style.display]="'none'"
formControlName="AssignedToColour">
<input
[style.display]="'none'"
formControlName="Id">
</div>
</div>
<div class="input-row row">
<div class="col-md-11">
<label for="{{'task' + i}}">Action:</label>
<div
[ngClass]="{'has-error': (tasks.get(i + '.Action').touched || tasks.get(i + '.Action').dirty) && !tasks.get(i + '.Action').valid }">
<textarea
rows="6"
id="{{'task' + i}}"
formControlName="Action"></textarea>
<span class="help-block" *ngIf="(tasks.get(i + '.Action').touched || tasks.get(i + '.Action').dirty) && tasks.get(i + '.Action').errors">
<span *ngIf="tasks.get(i + '.Action').errors.required">
Please enter a title.
</span>
</span>
</div>
</div>
<div class="col-md-1 text-center">
<label>Status</label>
<i *ngIf="tasks.get(i + '.Completed').value" class="glyphicon glyphicon-ok-sign ok" title="Completed"></i>
<i *ngIf="!tasks.get(i + '.Completed').value && !tasks.get(i + '.OverDue').value" class="glyphicon glyphicon-minus-sign pending" title="In progress"></i>
<i *ngIf="!tasks.get(i + '.Completed').value && tasks.get(i + '.OverDue').value" class="glyphicon glyphicon-exclamation-sign text-danger" title="Overdue!"></i>
</div>
</div>
<div class="input-row row">
<div class="col-md-3 assigned-to">
<div
[ngClass]="{'has-error': (tasks.get(i + '.AssignedToId').touched || tasks.get(i + '.AssignedToId').dirty) && !tasks.get(i + '.AssignedToId').valid }">
<label for="{{'assignedTo' + i}}">Assigned to:</label>
<div class="color-block" [style.background]="tasks.get(i + '.AssignedToColour').value"></div>
<label class="fa select">
<select
*ngIf="users"
id="{{'assignedTo' + i}}"
formControlName="AssignedToId">
<option
*ngFor="let user of users | trueValueFilter: 'IsActive'"
[value]="user.Id">{{user.Name}}</option>
</select>
</label>
<span class="help-block" *ngIf="(tasks.get(i + '.AssignedToId').touched || tasks.get(i + '.AssignedToId').dirty) && tasks.get(i + '.AssignedToId').errors">
<span *ngIf="tasks.get(i + '.AssignedToId').errors.required">
Please select a user.
</span>
</span>
</div>
</div>
<div class="col-md-3">
<div
[ngClass]="{'has-error': (tasks.get(i + '.DueDate').touched || tasks.get(i + '.DueDate').dirty) && !tasks.get(i + '.DueDate').valid }">
<label for="{{'dueDate' + i}}">Due date:</label>
<my-date-picker
class="datepicker"
type="text"
id="{{'dueDate' + i}}"
formControlName="DueDate"
[options]="myDatePickerOptions"></my-date-picker>
<span class="help-block" *ngIf="(tasks.get(i + '.DueDate').touched || tasks.get(i + '.DueDate').dirty) && tasks.get(i + '.DueDate').errors">
<span *ngIf="tasks.get(i + '.DueDate').errors.required">
Please set a due date.
</span>
</span>
</div>
</div>
<div class="col-md-2">
<label for="{{'reason' + i}}">Reason for change:</label>
<label class="fa select">
<select
class="reason-select"
*ngIf="reasons"
id="{{'reason' + i}}"
formControlName="ReasonForChangeId">
<option
*ngFor="let reason of reasons"
[value]="reason.Id">{{reason.Reason}}</option>
</select>
</label>
</div>
<div class="col-md-3">
<div class="text-center">
<label for="{{'OriginalDueDate' + i}}">Original due date:</label>
<span>{{tasks.get(i + '.OriginalDueDate').value | dateToStringFilter}}</span>
<input
readonly
type="text"
id="{{'OriginalDueDate' + i}}"
[style.display]="'none'"
formControlName="OriginalDueDate">
</div>
</div>
<div class="col-md-1">
<div class="text-center">
<label for="{{'completed' + i}}">Completed:</label>
<div class="checkbox-group">
<input type="checkbox"
type="checkbox"
id="{{'completed' + i}}"
formControlName="Completed">
<label class="checkbox" for="{{'completed' + i}}"></label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
<button
class="glyphicon glyphicon-plus-sign btn-icon add"
title="Insert task after this one"
(click)="insertTaskField(i)"></button>
<button
class="glyphicon glyphicon-remove-sign btn-icon delete"
title="Delete this task"
(click)="removeTaskField(i, tasks.get(i + '.Id')?.value)"></button>
<button
*ngIf="!tasks.get(i + '.Id').value"
(click)="saveNewTask(rfc.Id, i);"
[disabled]="!rfcActionTasksForm.valid"
class="pull-right">Save new</button>
<button
*ngIf="tasks.get(i + '.Id')?.value"
[disabled]="!rfcActionTasksForm.valid"
(click)="updateTask(i, tasks.get(i + '.Id')?.value)"
class="pull-right">Update</button>
</div>
</div>
</div>
</div>
</div>
<div class="row last">
<div class="col-md-12">
<button
class="pull-right"
[disabled]="enableUpdateAll === false"
(click)="reOrderTasks()">Update All</button>
</div>
</div>
</form>
I see multiple problems here:
A validator should be of the form:
(control: AbstractControl): {[key: string]: any} => {
if(isValid(control))
return null;
else
return {"myValidator":"invalid thing detected"};
}
You are returning undefined everytime so it can't work.
You cannot subscribe because it means everytime you make a change in your form, you resubscribe to the whole group's valuechanges, that's non-sense.
Forget about valueChanges, you need to do your control synchronously. Check if there is an error and use the setError() method of your children controls.
something like :
(group: FromGroup): {[key: string]: any} => {
if(!isValid(group)){
group.get("myChildControl").setErrors({"localError":"error detected !"});
return {"groupError":"error detected !"};
}
return null;
}
I'm not sure if you should use the second parameter of setError(errors,{emitEvent:false}) to avoid propagation or not.