I am implmenting the angular router in the hybrid mobile application.(Upgrading from ionic 3 to 4). One my scnerio, I want to pass the method as a query parameter to another page. For example, Call the page "studentEditPage" from "Student Detail Page" and passing the "Update" method name to student edit page. Before poping the "StudentEditPage", it calls the update method then pop. I am tring to pass the method in the queryparam in navigate but it does not accept it in ionic 4. Are we able to pass the method as a param in the queryparameters
From StudentDetailPage
let navigationExtras : NavigationExtras = {
state : {
param : { detail: "editcategory", value: studentName, callback: this.updateStudentCallback, }
}
}
that.router.navigate(['studentDetailsPage'],navigationExtras); Here "this.updateStudentCallback" as a method.
From StudentEditPage:
this.updateStudentCallback(tempEmpData).then(() => {
this.navigate.router(['studentEditPage'])
});
I have googled and searched the angular posts but unable to get the proper results. THanks in Advance.
Well you can id like this:
where you want send/pass id/param put id here on the app-routing.module.ts file
{ path: 'studentedit/:sid', loadChildren: './studentedit/studentedit.module#StudentEditPageModule'},
then in html file
<h1 (click)="gotoUpdate(std.studentID)" >click</h1>
in ts file
gotoProductlist(studentID: string) {
this.navCtrl.navigateForward('/studentUpdate/' + studentID);
}
in Edit Page
ngOnInit() {
// Get the ID that was passed with the URL
let id = this.activatedroute.snapshot.paramMap.get('sid');
}
Well you can get id from another page.
Related
I am forming a web app in lightning Community Experience Builder using LWC, which already has an URL that carries the domain of my org.
Now I want to handover the URL to users along with an Id appended to its end, such that when the user visits the site I can retrieve the Id from URL using JS.
example,
the original URL: cs-123.aig.lightning.force.com/form
User lands with: cs-123.aig.lightning.force.com/form?userId=123
I must be able to retrieve the userId when the component loads using renderedCallBack or connectedCallBack.
Thanks in advance.
Note:Lightning Navigation Service offered by LWC,doesnt work outside Salesforce,LEX.
Plain JavaScript URLSearchParams should be enough. I have something similar on my project and works ok in community, with LWC embedded on the page.
connectedCallback() {
// Try to read the preselected id from URL
if (window.location.href) {
try {
let url = new URL(window.location.href);
let id = url.searchParams.get('id');
if (id) {
this.userId = id;
}
} catch (e) {
if (console) {
console.log(JSON.stringify(e));
}
}
}
}
I have an editor page. When I add any content and click the "Save" button my URL will change, adding a random id in the URL. I want to check if my ID's are changing every time when I click the "Save button".
I save the URL result in variable and want to check it, I do it like this:
const currentURL = cy.url();
cy.get('.editor-toolbar-actions-save').click();
cy.url().should('not.eq', currentURL);
But my currentURL variable's type is not string:
expected http://localhost:8080/editor/37b44d4d-48b7-4d19-b3de-56b38fc9f951 to not equal { Object (chainerId, firstCall) }
How I can use my variable?
tl;dr
Cypress commands are asynchronous, you have to use then to work with their yields.
cy.url().then(url => {
cy.get('.editor-toolbar-actions-save').click();
cy.url().should('not.eq', url);
});
Explanation
A similar question was asked on GitHub, and the official document on aliases explains this phenomenon in great detail:
You cannot assign or work with the return values of any Cypress command. Commands are enqueued and run asynchronously.
The solution is shown too:
To access what each Cypress command yields you use .then().
cy.get('button').then(($btn) => {
// $btn is the object that the previous
// command yielded us
})
It is also a good idea to check out the core concepts docs's section on asynchronicity.
These commands return a chainable type, not primitive values like strings, so assigning them to variables will require further action to 'extract' the string.
In order to get the url string, you need to do
cy.url().then(urlString => //do whatever)
I have been having the same issue and so far most consistent method has been to save the URL to file and read it from file when you need to access it again:
//store the url into a file so that we can read it again elsewhere
cy.url().then(url => {
const saveLocation = `cypress/results/data/${Cypress.spec.name}.location.txt`
cy.writeFile(saveLocation, getUrl)
})
//elsewhere read the file and do thing with it
cy.readFile(`cypress/results/data/${Cypress.spec.name}.location.txt`).then((url) => {
cy.log(`returning back to editor ${url}`)
cy.visit(url)
})
Try this:
describe("Test Suite", () => {
let savedUrl;
beforeEach(() => {
cy.visit("https://duckduckgo.com/");
cy.url().then(($url) => {
savedUrl = $url;
});
});
it("Assert that theURL after the search doens't equal the URL before.", () => {
cy.get("#search_form_input_homepage").type("duck");
cy.get("#search_button_homepage").click();
// Check if this URL "https://duckduckgo.com/?q=duck&t=h_&ia=web"
// doesn't equal the saved URL "https://duckduckgo.com/"
cy.url().should("not.eq", savedUrl);
});
});
Refer below code snippet, Here you can get the current URL and store it in a variable, do print via cy.log()
context('Get Current URL', () => {
it('Get current url and print', () => {
cy.visit('https://docs.cypress.io/api/commands/url')
cy.url().then(url => {
const getUrl = url
cy.log('Current URL is : '+getUrl)
})
})
})
#Max thanks this helped to get some ideas on different versions.
The way I did it is:
Create a .json file in your fixtures folder (name it whatever you want).
On the new .json file, only add: { } brackets and leave the rest blank. The function will self populate that .json file.
Create a new function on the commands page to easily call it on your test.
It would probably be best to create two functions, 1 function to write url or the sliced piece of the url, and the another function to call it so you can use it.
A. Example of 1st method, this method cuts the id off of the URL and stores it on the .json file:
Cypress.Commands.add('writeToJSON', (nameOfJSONSlicedSection) =>
{
cy.url().then(urlID =>
{
let urlBit = urlID.slice(urlID.indexOf('s/') + 2, urlID.indexOf('/edit'))
cy.writeFile('cypress/fixtures/XYZ.json', {name: nameOfJSONSlicedSection, id: urlBit}) /*{ }<-- these will populate the json file with name: xxxxx and id:xxxxx, you can changes those to whatever meets your requirements. using .slice() to take a section of the url. I needed the id that is on the url, so I cut only that section out and put it on the json file.*/
})
})
B. 2nd example function of calling it to be used.
This function is to type in the id that is on the url into a search box, to find the item I require on a different it() block.
Cypress.Commands.add('readJSONFile', (storedJSONFile) =>
{
cy.readFile('cypress/fixtures/XYZ.json').its('id').then((urlSetter) => {
cy.log(storedJSONFile, 'returning ID: ' + urlSetter)
//Search for Story
cy.get('Search text box').should('be.visible').type(urlSetter, {delay: 75})
})
})
/*here I use a .then() and hold the "id" with "urlSetter", then I type it in the search box to find it by the id that is in the URL. Also note that using ".its()" you can call any part section you require, example: .its('name') or .its('id') */
I hope this helps!
I am using $this->redirect to redirect from one action to another
$this->redirect(array('site/payment','bookingID'=>$bookingID,'orderID'=>$model->quoteNo,'amount'=>$rent));
But I don't why it showing parameter in url
https://www.siteurl.com/bookingID/5/orderID/123456/amount/220.00
How do I hide my data from user?
You can do it using sessions. You can access current Session with Yii::$app->session. You can send those parameters in session.. For Example
public function actionOne() {
// Check if the Session is Open, and Open it if it isn't Open already
if (!Yii::$app->session->getIsActive()) {
Yii::$app->session->open();
}
Yii::$app->session['bookingID'] = $bookingID;
Yii::$app->session['orderID'] = $model->quoteNo;
Yii::$app->session['amount'] = $rent;
Yii::$app->session->close();
$this->redirect(['site/payment']);
}
public function actionTwo() {
// Then you can get those values like this...
$bookingID= Yii::$app->session['bookingID'];
$orderID= Yii::$app->session['orderID'];
$amount= Yii::$app->session['amount'];
// do whatever you want..
}
I have a rails controller for recipes. I have added some additional variable called #recID. I am able to access this variable successfully in index.json.jbuilder.
I can't figure out how to access it in my app.js (which is angular controller file).
My research has covered:
How can i pass a scope variable from controller to directive in angular js
How can controller talk to a directive in AngularJS?
and many other google searches.
Here is a code snippet in from app.js:
$scope.search = function(keywords) {
return $location.path("/").search('keywords', keywords);
};
// query = $resource('/', {query: "query"});
// query = $resource('/recipes/:recipeId', {
query = $resource('/', {
query: "#recID",
format: 'json'
});
console.log ("About to write to log query=" + query);
// alert ("query =<" + query + ">");
Recipe = $resource('/recipes/:recipeId', {
recipeId: "#id",
format: 'json'
});
try using gon.gon is a gemused to pass data to js.first you need to install gon.then in your controller you can specify
gon.variable_name = variable_value
in your js
gon.variable_name
https://github.com/gazay/gon
https://gist.github.com/shicholas/5937417
You can set some hidden_field in the HTML with controller variable value and fetch this value in app.js using DOM selector.
Im trying to create an ajax (post) event that will populate a table in a div on button click.
I have a list of groups, when you click on a group, I would like the table to "disappear" and the members that belong to that group to "appear".
My problem comes up when using jQuery's .ajax...
When I click on the button, it is looking for a controller that doesnt exist, and a controller that is NOT referenced. I am, however, using AREAS (MVC2), and the area is named Member_Select where the controller is named MemberSelect. When I click on the button, I get a 404 stating it cannot find the controller Member_Select. I have examined the link button and it is set to Member_Select when clicked on, but here's the ajax call:
$.ajax({
type: "POST",
url: '/MemberSelect/GetMembersFromGroup',
success: function(html) { $("#groupResults").html(html); }
});
I havent been able to find any examples/help online.
Any thoughts/suggestions/hints would be greatly appreciated.
Thanks!
Have you tried navigating to /MemberSelect/GetMembersFromGroup to see what you get? - if it's 404'ing it's because the route can't be matched to a controller/ action.
I've not used the new areas functionality, but I'm not sure that the URL you've got is correct...I would have thought it would have been /AREANAME/MemberSelect/GetMembersFromGroup...but I could be wrong..!
When I did this, it worked fine. I didn't use POST and I don't know what AREAS means.
$("#item").autocomplete({
source: function(req, responseFn) {
addMessage("search on: '" + req.term + "'<br/>", true);
$.ajax({
url : ajaxUrlBase1 + "GetMatchedCities/" + req.term,
cache : false,
type : "GET", // http method
success : function(msg){
// ajax call has returned
var result = msg;
var a = [];
if (result !== null){
for(var i=0; i < result.length; i++) {
a.push({label: result[i].prop1, id: result[i].prop2});
}
}
responseFn(a);
}
});
}
});
Use:
area_name/controller_name/action_name
Instead of doing $.ajax I would use jQuery Form Plugin.
and have my form set as:
Html.BeginForm("Index","AdminArea/Admin",FormMethod.Post,
new { id="form-user", name="form-user"})
To use jQuery Form Plugin have a look here:
http://arturito.net/2010/12/02/asp-net-mvc2-jquery-form-post-tutorial/
You cold save your url in a Hidden Form element in (Html.HiddenForm()) and use the #id javascript operator to retrieve it. Just found this out today.