Hide/Disable Edit button based on column's Values in Sharepoint 2010 - javascript

I have a column that has 2 Categories, Done and Pending. I would like to Hide/Disable edit button once the user selects an item and if that item has a Status column of "Pending".
I would like to know how can this be done, whether in visual studio 2010 or ECMA Scripts.

I know this question is old but if someone still needs the answer:
Create a custom action in visual studio like this:
https://msdn.microsoft.com/en-us/library/office/ff408060(v=office.14).aspx
This hides the button you want, now you can set a condition via enabledscript parameter to choose in which case the button should be hidden:
Just add this code after </CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="HideEditRibbon"
CommandAction="javascript:return true;" EnabledScript="javascript:checkIfNeedsToBeHidden();" />
</CommandUIHandlers>
<CustomAction Id="yourJsReference" Location="ScriptLink" ScriptSrc="yourJsFile.js"></CustomAction>
If you need this in List-Ribbon, Edit and DisplayForm, you need to make 3 Custom Actions and change the Location-Part and maybe your js-code.

If you want to use an out of the box edit form then you're not going to do this with server side code; you'd need an entirely custom edit form to do that.
This means using Javascript on the edit page, which is fragile, and doesn't prevent users from saving the data if they know what they're doing.
The input field for every column will have a 'title' attribute with the column name. JQuery can find the element with title='column name' rather easily, so that's how you'll know if you need to hide the save button. The save button isn't quite as easy to get to. You could try getting the input with type=button and value=save.
If it's important to have actual security around this, so that no matter what someone can't edit an item in this state then you can use an event receiver on the ItemUpdating event. Just check the properties of the item and use the properties.Cancel = true; (or something like that) so that even if they disable your JavaScript and save the event anyway, it won't get saved. If you need help adding an event receiver or getting it working just ask.
Edit: In your comment that you say you just want to prevent access to the edit form entirely under certain conditions. For that, I'd make a new webpart/user control and add it to the edit page. In that section you can fetch the appropriate item (the ID of the item will be a query parameter) and see if the page should be 'viewable'. If not, then you can redirect to another page.
Another addition to the above would be attempting to edit the list view such that there is no edit link for certain items. This would be substantially harder, and I doubt it would even be possible (practically) with out of the box webparts. You would need to have an entirely custom list view page in order to control which items have links to an edit page. (Others feel free to correct me here.)

Related

Change value in table on Button click in Acumatica

I am creating a Scan In and Out form in Acumatica as a custom screen. They are two separate screens and both are just a standard form.
They are both setup as follows: One field that is a selector where you select the Key ID of the data row you want to modify such as a Work Order. Once you click Scan In it will change the value of a field in that data row for the Key ID you selected let's say, the status field saying that it is being processed for Scan In button click and closed for the Scan Out button click.
My question is, is it possible to do this with just a click event. I mean the save button commits changes to the database but this does not have a save and is only changing one field of a specific data row.
If anyone has suggestions or can point me in the right direction that would be great! Again this is all in Acumatica so I feel the Graph or View will have to be modified?
Once in my company we did something similar, i know this is not the best option based on acumatica way, but what we did is to execute a direct SQL query from the action (in your case the click button) to update/insert something in database. I think the best option for you would be use Ajax, but i don't know if acumatica has this functionality.
In your action that is changing the status of the row, after changing the status, you can call an update to your view (ViewName.Update(targetRow)) that is used to populate the page with the information you are looking at. After you can programmatically trigger a page save using this.Actions.PressSave().

How to match a button push in a table of buttons to specific data on the server?

If you believe the title can be edited please feel free to do so.
I have small web app that's used to search for entries in a database. You are given a table of entries, and you can click on one of those entries to expand it down (accordion) to view more details.
I want to add a few buttons to manipulate the entries in different ways, however, I am not sure how to pass information from the button click to a javascript function that I can use to identify and change the data in the database. Pretty much there may be 50 rows in the table, but I want to identify which one the button was pushed in (specifically something that can be used to uniquely identify the row in the database, not in the HTML table).
How/what should I pass to a function when the button is clicked?
I apologize if this is too broad, I have absolutely no idea where to start, any guidance is welcome.
Everything depends on how you submit button click to the server. If you do this with ajax call then the simplest solution will be to add entry id to the request. You can add this id to the table row with data-entry-id="{id_from_table}" and then retrieve it in js. If your buttons are simple links then you can change it to button/input with type submit and wrap it with form which would have hidden field of entry_id.

Auto update table fields and disabled function using javaScript, Ruby on Rails and/or JQuery

Versions
Mac OS: OSX 10.10.2
Ruby: 2.2.1p85
Rails: 4.2.0
Bootstrap-SASS: 3.3.4 #For Web UI
Bootstrap-Switch-Rails: 3.0.0 #For Toggles
Context
I am building a site where someone can create a packing event to make bags for the homeless. I am using Ruby on Rails to create this webapp, Bootstrap to design the user interface, and am open to using JQuery, javaScript, HTML, and CSS to get the desired functionality. Though my working knowledge of the first two languages is minimal.
In the user's event creation and edit pages I have a list of items that a person can add to their bags. This list is in a table view as seen through the link below.
Dropbox link
Desired Functionality
I am wanting to do 2 things.
When the user enters the number of bags they plan on packing, I want to be able to update the column "Number Needed" for each item. So, for instance in the example scenario shown in the image above, the "Number Needed" for "Raise Money" would be "$6,500", for "Volunteers" would not be added, for "Water" would be "1000" and for "Food" would be "1000".
I want the user to be able to toggle whether to include an item on their event page. So, in the example picture, the user wants to show on their event page that they are raising money for their event, and requesting donations for water and food; but they do not need volunteers to pack the bags. In this scenario, I would like to disable the form fields of "Number Needed", "Currently Have" and "Number Remaining to Get" for the row "Volunteers".
Questions
For the first desired functionality specified above: Should I just have the table on a separate page maybe so that the fields are populated before the table is actually shown? Or, my preferred ability, do I need to put a button after the "Number of Bags" field that when clicked updates the table? And how would I do that?
For the second desired functionality specified above: Is there a way to have this done dynamically when the user toggles the "Include" column to "Yes" or "No"? How would I disable the desired form fields dynamically once a user toggles that row to "No"?
Let me know if you need any more information. And thank you in advance for your expertise.
First things first, I would put this in the comment, but I don't have enough reputation to do that yet.
Ok so there's a few ways to solve your problem. The first and ugly solution would be to rerender the page everytime something gets updated. You really shouldn't do it that way because that required the user to hit a button to submit the form and the controller would render the same page again with updated results.
Instead, you want to use jQuery to add event listeners to your form fields and the button mentioned in the second functionality. On those event listeners, put some handlers to update the desired field. It's hard to direct you on the jQuery if I don't know your HTML structure. As Santiago mentioned, there are many tutorials out on the internet for putting event listeners and creating the proper handlers.
Additionally, you should consider AJAX to asynchronously communicate with your controller to keep the front-end (what the users see on the browser) and the back-end (data stored in the database) in sync. Again, plenty of guides out there on the internet for this, but definitely look into the Rails functionality of "remote: true" on your form to make the set up of the AJAX process easier.

setSubmitMode method behaving differently between users

I have two custom picklists: types and duration. The types pick list has two options and the duration has three. Based on what he picks in the types picklist, one of two variables will pass to the OOTB description text box. And based on what he picks in both of the picklists, one of six variables will pass to a custom warranty text box. Both of the text boxes are editable so he can tweak the paragraph-long variables as needed.
Problem 1: The setSubmitMode method was not present at first. When it was not present, he could not revise a quote.
Solution 1: I set the setSubmitMode to 'always' on the OnChange events.
Problem 2: When he tried to revise the quote it would throw a Read-Only error but still would allow him to revise and save the quote.
Solution 2: I set the setSubmitMode to 'dirty' on the OnChange events and added an OnSave event with a setSubmitMode to 'always'.
Problem 3: When he tries to revise the quote he gets a "Do you want to save your changes" dialog box. When he click "yes" it wipes out his changes and when he click "no" the Quote allows him to revise it... I can not produce the dialog box that a user is getting.
We've tried this in CRM for Outlook and in the browser.
If it helps to know, in both of our set-ups, it looks like it opens a new Quote window. In mine, however, the new window immediately closes without the dialog box in Outlook. But in the browser, it closes the original form too. (This isn't ideal but still is better than what he's getting.)
Thanks & Regards,
M
I'm not sure to exactly understand your issue but for those kinds of problem, I always used the same solution. On the OnSave event, i've this code to save read-only fields edited by the javascript :
if (Xrm.Page.getAttribute("my_field").getIsDirty()) {
Xrm.Page.getAttribute("my_field").setSubmitMode("always");
}
No setSubmitMode("dirty"), or anything else. Even on the onChange event.
I hope it helps, otherwise don't hesitate to add more infos about your process.
Kévin

javascript form validation in rails?

I was wondering how to go about form validation in rails. Specifically, here is what I'm trying to do:
The form lets the user select an item from a drop down menu, and then enter a number along with it. Using RJS, the record instantly shows up in a table below the form. Resetting the form with AJAX isn't a problem.
The issue is, I don't want the person to be able to select the same item from that drop down menu twice (in 1 day at least). Without using ajax, this isn't a problem (as I have a function for the select statement currently), but now that the page isn't reloading, I need a way to make sure people cant add the same item twice in one day.
That said, is there a way to use some javascript/ajax validation to make sure the same record hasn't been submitted during that day, before a duplicate can be created?
Thanks in advance!
Elliot
With regards to form validations, for your special logic, you'll want to override #validate in your model. See the docs for ActiveRecord::Validations#validate.
Your best bet to "make sure people cant add the same item twice in one day" is to not present the user with options that they can't select. When your controller prepares data for the view have logic that filters out any options that the user shouldn't have (i.e. those they already selected that day). Or present them but disable them as options (so they are grayed out). If the user could select the same option twice in one request you'll want some JS to do client-side validation before a POST to the server.

Categories