sending ids to controller and saving..? - salesforce

<apex:commandlink action="{!removeline}" onclick="if(confirm('Are you sure?')) " reRender="thePB" target="_top" > <img src="{!$Resource.Red_Cross}" alt="Remove" title="Remove" />
<apex:param name="deleteid" value="{!op.Id}" assignTo="{!deleteid}"/>
</apex:commandlink >
I have cross image in front of every record.on click of that i am sending id to the controller.but the problem is when i click on cross 2 records and then click on delete button only 1 record is deleted.Can anyone suggest me how to save ids(more than 1 record) in controller and delete records on delete click.I am learning salesforce

You can use with the actionFunction and send the ids ​​by javaScript
Something like
<script>
function removelines(){
var deleteIds = ....;
removeline(deleteIds )
</script>
<input type="button" class="btn" onClick="onclick="if(confirm('Are you sure?'))"/>
<apex:actionFunction action="{!removeline}" name="removeline">
<apex:param name="deleteIds" assignTo="{!deleteIds}" value="" />
</apex:actionFunction>

Related

Confirm overwrite/delete? (appengine jinja2 python)

I'm developing an app for production planning in a factory using appengine/jinja2 and am stuck with how to ask the user to confirm if the app should overwrite existing data or delete an entity in the NDB.
Maybe someone can suggest a course of action?
In product_edit.py I do the following (simplified):
RequestHandler
...
execute query and find given product
template_values = {
'prod_id': query.prod_id,
'prod_desc': query.prod_desc,
}
template = JINJA_ENVIRONMENT.get_template('/html/product_edit.html')
self.response.write(template.render(template_values))
The product_edit.html file looks like below (I'm using w3.css).
...
<form class="w3-container" action="/products-save" method="post">
<label class="w3-text-blue"><b>Product ID</b></label>
<input value="{{prod_id}}" name="prod_id_txt" size="15" class="w3-input w3-border">
<br>
<label class="w3-text-blue"><b>Product Description</b></label>
<input value="{{prod_desc}}" name="prod_(I'm using w3.css)desc_txt" size="50"
<input class="w3-btn w3-blue" type="submit" value="Save">
</form>
It populates two inputs with the product ID and description coming from the NDB and provides a "Save" button.
The save invokes the appropriate request handler to write to the NDB. So I can overwrite the existing NDB entity, no probs.
But how can I ask the user to confirm before overwriting (or deleting) existing data?
In the product-save request handler I can of course display a page asking the user to confirm, but in doing this I lose the data from the original POST.
One option would be to send the data to the new Jinja2 template via hidden fields, and upon user confirmation save the data from the hidden fields. However, this would not win a code beuty contest and is prone to coding errors. Is there anything more elegant I could do?
For the delete form I could do something with a pop-up to ask for confirmation, but I would like to use the same method as for the edit so that they are visually similar.
Thanks in advance!
There are many ways to accomplish this. The most straightforward way is to wire the form submit through a javascript function before submitting. Change:
<input class="w3-btn w3-blue" type="submit" value="Save">
to
<div id="saveWithConfirm">
<input class="w3-btn w3-blue" type="button" value="Save" onclick="confirmOverwrite('ask');" />
</div>
then:
function confirmOverwrite(confirm) {
confirmDiv = document.getElementById("saveWithConfirm");
if ( confirm == "confirmed" ) {
document.getElementById("ID-of-Form-Here").submit();
} else if ( confirm == "ask" ) {
//... if you need to check the database first, do an ajax call here...
confirmDiv.innerHTML = '<input class="w3-btn w3-blue" type="button" value="No" onclick="confirmOverwrite(\'no\');" /><input class="w3-btn w3-blue" type="button" value="Yes" onclick="confirmOverwrite(\'confirmed\');" /> ';
} else {
confirmDiv.innerHTML = '<input class="w3-btn w3-blue" type="button" value="Save" onclick="confirmOverwrite(\'ask\');" /> ';
}
}
This way, you never leave the form.

angular and asp.net mvc delete with post

I currently have the following grid on my page:
<tr ng-repeat="cartItem in vm.shoppingCart">
<td>{{cartItem.Title}}</td>
<td>
#using (Html.BeginForm("Delete", "MyController", FormMethod.Post))
{
#Html.AntiForgeryToken()
<input type="submit" value="Delete" id="DeleteBtn" name="DeleteBtn" class="btn blue" />
}
</td>
Our users have requested that the delete happen with a post to the server, so we setup a form in the grid, i'm not sure if that's the best way to go about it. also how would we pass in the Id (cartItem.Id) of the item to delete to the action? Is it common to have a form in each row like this? otherwise we can convince the users to do it through client side.

how to redirect the selected json value to another page using angularjs

<tr ng-if="usernames.length" ng-repeat="user in usernames">
<td><input type="radio" name="radio" ng-model="form.currentPatient" value="{{user}}" id="{{user.id}}"></td>
<td>{{user.firstname}} </td>
<td>{{user.lastname}}</td>
<td>{{user.address}}</td>
<td>{{user.age}}</td>
</tr>
</table>
<div>{{form.currentPatient}}</div>
<button type="submit" value="View Profile" onclick="location.href('result.html' )">View Profile</button>
If I click on that radio button ,the corresponding json values should be redirect to the result page
Please help me ......
If not using routeprovider
You can create shared service or factory to store value and retrive in other pages.
If using routeprovider
You can bind JSON value in URl this way-:
window.location="#/result/firstname="+$scope.user.firstname+"&&lastname="+$scope.user.lastname+"&&age="+$scope.user.age; And You can access this value as $location.search()['firstname'], $location.search()['lastname'], $location.search()['age']
you can access this value as-:
$location.search()['firstname'] for firstname,
$location.search()['lastname'] for lastname and
$location.search()['age'] for age
you can add $location in function like as $scope .

apex inputText value null in controller

I have an input filed that I am attempting to pass the end user's entered input into the SF controller class.
Below is the inputText visualforce code:
<div class="ssa-inputs">
<div class="ssa-input-text">Name: </div>
<div class="ssa-input">
<apex:form>
<apex:inputText value="{!acknowledgeInput}" id="acknowledgeInput"/>
</apex:form>
</div>
</div>
<div class="ssa-btns">
<div class="ssa-btn">
<apex:form>
<apex:commandButton id="acceptHidden" value="Accept" action="{!updatecontact}"/>
</apex:form>
<input type="submit" id="acceptBtn" value="Accept"/>
</div>
<div class="ssa-btn">
<apex:form>
<apex:commandButton value="Decline" action="{!updatecontact}"/>
</apex:form>
</div>
</div>
Below is the SF controller code:
public string acknowledgeInput{get;set;}
public PageReference updatecontact(){
System.debug(LoggingLevel.DEBUG, acknowledgeInput);
// Update contact information
// Redirect to respected PageReference
}
When I try to print out the value in the logs, I receive null.
I feel like this is pretty straight forward and I can't seem to find what I'm missing.
Thanks
You need to have the command button and input text field in the same form.

Why is click ignored on non-Angular page in a Protractor test?

I have an app I'm trying to do e2e tests with. The app uses a non-Angular login page (Microsoft AD account). So, I fill in the user and password then click the "sign in" button with the following code:
var user = asAdmin ? config.adminUser : config.user;
browser.driver.findElement(by.id('cred_userid_inputtext')).sendKeys(user);
browser.driver.findElement(by.id('cred_password_inputtext')).sendKeys(config.pass);
browser.driver.findElement(by.id('cred_sign_in_button')).click();
The user and password get filled in and the "sign in" button (which is a <span>) looks like it was clicked (changes color), but nothing happens.
I wait for quite a while (minutes) and it just doesn't work. However, if I just use the mouse, it does work. I have also tried tacking on a "\n" to the end of the password string to simulate the enter key. This is ignored.
The html for the pertinent parts of the login look like this:
<form id="credentials" method="post" action="https://login.microsoftonline.com/...">
<div id="cred_userid_container" class="login_textfield textfield">
<span class="input_field textfield">
<label for="cred_userid_inputtext" class="no_display" aria-hidden="true">User account</label>
<div class="input_border">
<input tabindex="1" id="cred_userid_inputtext" class="login_textfield textfield required email field normaltext" placeholder="someone#example.com " type="email" name="login" spellcheck="false" alt="someone#example.com " aria-label="User account" value="" autocomplete="off">
</div>
</span>
</div>
...
<div id="cred_password_container" class="login_textfield textfield" style="opacity: 1;">
<span class="input_field textfield">
<label for="cred_password_inputtext" class="no_display" aria-hidden="true">Password</label>
<div class="input_border">
<input tabindex="2" id="cred_password_inputtext" class="login_textfield textfield required field normaltext" placeholder="Password" spellcheck="false" aria-label="Password" alt="Password" type="password" name="passwd" value="">
</div>
</span>
</div>
...
<li class="login_cred_options_container">
<div id="cred_kmsi_container" class="subtext normaltext">
<span class="input_field ">
<input tabindex="10" id="cred_keep_me_signed_in_checkbox" type="checkbox" value="0" name="persist">
<label id="keep_me_signed_in_label_text" for="cred_keep_me_signed_in_checkbox" class="persist_text">Keep me signed in</label>
</span>
</div>
<span id="cred_sign_in_button" tabindex="11" onclick="Post.SubmitCreds();return false;" class="button normaltext cred_sign_in_button refresh_domain_state disabled_button" role="button" style="opacity: 1;">Sign in</span>
<div id="recover_container" class="subtext smalltext" style="opacity: 1;">
<span>
<a id="cred_forgot_password_link" tabindex="12" href="https://login.microsoftonline.com/resetpw.srf?lc=1033&id=501148">Can’t access your account?</a>
</span>
</div>
</li>
...
</form>
I can't, for the life of me figure out what's going on here.
Any help is greatly appreciated.
UPDATED: added the missing "button" span
UPDATE 2: also tested with Firefox, same problem. The click on the span just doesn't seem to work..
UPDATE 3: For some strange reason, the following code works:
browser.actions()
.mouseMove(browser.driver.findElement(by.id('cred_sign_in_button')))
.click()
.perform();
browser.sleep(500);
browser.driver.findElement(by.id('cred_sign_in_button')).click();
If I take either the mouseMove/click or the last click out, it stops working. If I take out the sleep, it is intermittent.
I have no idea why that's working.
Testing non-angular pages with Protractor can be tricky regarding waiting for stuff.
I suggest you upgrade Protractor to latest (1.3.1 as of now), use a custom function waitReady() that browser.wait for elements ready and rewrite your test like this:
var user = asAdmin ? config.adminUser : config.user;
// TODO: use page objects
var userIdInputElm = $('#cred_userid_inputtext');
var passwordInputElm = $('#cred_password_inputtext');
var signinButtonElm = $('#cred_sign_in_button');
it('waits for the elements present and visible (non-angular)', function() {
expect(userIdInputElm.waitReady()).toBeTruthy();
expect(passwordInputElm.waitReady()).toBeTruthy();
expect(signinButtonElm.waitReady()).toBeTruthy();
});
it('fills user and password', function() {
userIdInputElm.sendKeys(user);
passwordInputElm.sendKeys(config.pass);
});
it('clicks sign in button', function() {
signinButtonElm.click();
});
More details of why waitReady here.

Resources