Hey Zach I’m trying to use this code but it doesn’t seem to be doing anything for me. I’m trying to remove a picklist value, but it keeps showing up… here is my snippet:
var field = arguments[0], value = skuid.utils.decodeHTML(arguments[1]); var picklistEntries = field.metadata.picklistEntries; picklistEntries.length = 0; // if you don't do this, then the "real" values are already in the picklist and the code below will add duplicate values picklistEntries.push( { value: 'Fixed', label: 'Fixed', defaultValue: false, active: true }, { value: 'Indexed', label: 'Indexed', defaultValue: false, active: true } ); // Run the standard picklist renderer for the given mode skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
If I log it in the console I can see that my changes have been made, however it doesn’t reflect on the page…
Moshe, one “wrinkle” to the Picklist renderer is that if the Picklist is either (a) Dependent on the values of another picklist, or (b) Dependent on the record’s Record Type, then field.metadata.picklistEntries is NOT considered when building the Picklist — rather, an internal function is run that goes and determines the appropriate values to display based on the value of the controlling picklist and/or Record Type field on the current record.
If you want to completely override this behavior, you’ll need to roll your own custom picklist renderer using our internal skuid.ui.renderers API, and as J describes in this community post.
If you want to rely on the internal renderer, but adjust the values AFTER the renderer has been run, you might try removing the displayed values directly from the output
It sounds like your snippet isn’t getting passed the field as arguments[0]. How are you launching you snippet? This code will only work if you’re running it as a custom field renderer.
I asked this in a comment above, though have not found a reply and am still stuck with it. How do I modify the snippet to render radio buttons instead of the standard picklist dropdown?
Thank you!
var $ = skuid.$; var field = arguments[0], value = skuid.utils.decodeHTML(arguments[1]); skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value); var select = field.element.find('select'); if (select.length) { $.each(select.children('option'),function(){ if ($(this).val() === 'Survey Complete - Qualified' || $(this).val() === 'Sent' || $(this).val() === 'Responded' || $(this).val() === 'Survey Complete - DNQ' || $(this).val() === 'Appointment Booked'){ $(this).remove(); } }); }<br>
var field = arguments[0], row = field.row, // set the render condition isPercentage = (row.Indicator__r.Benchmark_Type__c == 'Percentage') ? true : false; value = skuid.utils.decodeHTML(arguments[1]), metadata = field.metadata, element = field.item.element, $ = skuid.$; if (isPercentage && field.mode =='edit'){ //create a blank variable for picklist entries var picklistEntries = []; // set the picklist entries. note defaultValue doesn't matter, the first one will be default picklistEntries.push( { value: '0', label: 'No', defaultValue: true, active: true }, { value: '1', label: 'Yes', defaultValue: false, active: true } ); field.metadata.picklistEntries = picklistEntries; // render the field as a picklist skuid.ui.fieldRenderers.PICKLIST.edit(field,value); } else{ //use the default renderer skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value); }<br>
Amazing, thank you for the help! I can now render the options as radio buttons (YAY!). As an added challenge, I would still like to remove unwanted entries. The existing script as suggested earlier does not seem to do the trick any more once the list is rendered as radio buttons. How would I have to modify this code to remove them?
I am trying to render a custom picklist but the picklist is just rendering as normal and there are no errors in the console. Can some one point in the right
Objective: If the running user has a sales category of “Retail Sales” then only show the “Retail Sales” option in the picklist. Otherwise render as usual.
Notes: This is a dependent picklist.
Code:
var $ = skuid.$; var field = arguments[0], value = skuid.utils.decodeHTML(arguments[1]); var isRetailSales = []; var userModel = skuid.model.getModel('RunningUser'), quoteModel = skuid.model.getModel('QuoteDetail'), userRow = userModel.getFirstRow(), userSalesCategory = userModel.getFieldValue(userRow,'AC_Sales_Category__c'), isRetailSales = (userSalesCategory == "Retail Sales"); skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value); var select = field.element.find('select'); if (isRetailSales && field.mode == 'edit') { if (select.length) { // Remove unwanted entries $.each(select.children('option'),function(){ if ($(this).val() === 'Retail Sales'){ $(this).remove(); } }); } }<br>
It looks like your code is removing the value is the value === ‘Retail Sales’, but from your description, you’re looking to do the opposite. Try changing === to !==
if (isRetailSales && field.mode == 'edit') {<br /> if (select.length) { // Remove unwanted entries $.each(select.children('option'),function(){ if ($(this).val() <b>!==</b> 'Retail Sales'){ $(this).remove(); } }); } }
if (isRetailSales && field.mode == 'edit') {
I’m no JS whiz but I think that first one might need ===
Also you might try inserting some console.log lines at various junctures. Like after isRetailSales definition, console.log('Is Retail Sales? '+isRetailSales), and maybe also after select.length to get the length of your picklist and make sure that is coming in right, and maybe also in the $.each loop, log the value of each picklist value so you can see what it’s capturing. That might help you find an error somewhere.