Button change text display every after click - button

I am new in Google script. Could you please help me on this.
I want to create a button in googlesheet with series of text display every after click.
( I dont know what to put in script)
OPEN (green background) --> CLICK--> CLOSE ( red background) --> CLICK--> OPEN (green background)...and so on
Thank you in advance

I believe your goal as follows.
You want to achieve the button which is changed when the button is clicked on the Google Spreadsheet.
For example, when the button with the green color and "OPEN" text is clicked, you want to change it to the button with the red color and "CLOSE" text.
You want to achieve this using Google Apps Script.
Issue and workarounds:
In the current stage, unfortunately, Google Apps Script cannot directly manage the drawing on Google Spreadsheet by editing the text and color. So it is required to think of the workaround for achieving your goal. In this answer, I would like to propose the following 3 workarounds as the methodology.
Workaround 1:
In this workaround, the drawing is used as the button. When the drawing is used as the button, 2 drawings are prepared and both drawings are overwrapped. Each button has the function of button1 and button2, respectively. When a button is clicked, the z index is replaced. By this, the switching button can be achieved. Because in the current stage, the image cannot be directly edited by the Google Apps Script.
Usage:
In order to use the sample script, create 2 buttons as the drawings like the above demo image.
In this case, please overwrap the both drawings.
Please assign the function of button1 and button2 to each button.
Copy and paste the following script to the container-bound script of Spreadsheet and save it.
const button1 = () => switching("button1");
const button2 = () => switching("button2");
function switching(name) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const drawings = sheet.getDrawings();
drawings.forEach(d => d.setZIndex(d.getOnAction() == name ? 0 : 1));
const temp = ss.insertSheet();
SpreadsheetApp.flush();
ss.deleteSheet(temp);
sheet.activate();
}
Click the button. By this, the script is run and the button is switched.
Note:
In this case, in order to refresh the change of z index of drawings, it is required to change the focus to other sheet. By this, when the button is clicked, the button is flashing in a moment. About this, I would like to expect the future update.
Workaround 2:
In this pattern, the drawing is used as the button. In this case, 2 drawings are also prepared, and one button is put to the cell "C3" and another one is other position (as the test, the button is put to "E10".) in the same sheet. Each button has the function of button1 and button2, respectively. When a button is clicked, the clicked button is replaced with the button of the another position. By this, the switching button can be achieved.
Usage:
In order to use the sample script, create 2 buttons as the drawings like the above demo image.
In this case, please put a button to the cell "C3" and another one to other position (as the test, the button is put to "E10".) in the same sheet.
Please assign the function of button1 and button2 to each button.
Copy and paste the following script to the container-bound script of Spreadsheet and save it.
const button1 = () => switching("button1");
const button2 = () => switching("button2");
function switching(name) {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const drawings = sheet.getDrawings();
if (drawings[0].getOnAction() == name) {
drawings[1].setPosition(3, 3, 0, 0);
drawings[0].setPosition(10, 5, 0, 0);
} else {
drawings[0].setPosition(3, 3, 0, 0);
drawings[1].setPosition(10, 5, 0, 0);
}
}
Click the button. By this, the script is run and the button is switched.
Note
In this case, it is not required to refresh by focusing to other sheet. But, another button is required to be put to the same sheet.
Workaround 3:
In this workaround, the cell is used as the button. When the cell is used as the button, in this case, the cell "C3" is used. And the OnSelectionChange event trigger is used for executing the script.
Usage:
In order to use the sample script, put the text of "OPEN" and the red color to the cell "C3" like above demo image.
Copy and paste the following script to the container-bound script of Spreadsheet and save it.
function onSelectionChange(e) {
const range = e.range;
const sheet = range.getSheet();
const a1Notation = range.getA1Notation();
if (a1Notation == "C3") {
if (range.getValue() == "OPEN") {
range.setBackground("#ff0000");
range.setValue("CLOSE");
} else {
range.setBackground("#38761d");
range.setValue("OPEN");
}
sheet.getRange("A1").activate();
}
}
Click the cell "C3". By this, the script is run and the text and color of the cell are switched.
Note
In this case, in order to select the button again, it is required to change the selected cell. This is the current specification.
Note:
These are the simple sample scripts. So please modify them for your actual situation.
References:
Class Drawing
Simple Triggers

Related

Adding button to lightningchart

I am adding UIelement by using following code
legendBox = chart[unique].addUIElement(UILayoutBuilders.Column.setBackground( UIBackgrounds.Rectangle ))
.setPosition({ x: 0, y: 100 })
.setOrigin(UIOrigins.LeftTop)
Right now I am able to add series to it by following code
entry = legendBox.addElement(UIElementBuilders.CheckBox);
series.attach(entry);
Instead , can I add the button with some value ? On clicking of that button I need call an function with that value.
For example if I add button with value
<button val="22">Click<button>
Now when i click that button , I need a callback function returning 22.Is it possible ?
In your case, the entry variable is of type UICheckBox.
To apply a custom action when clicking it, the onSwitch method should do it.
series.attach(entry); is only required if you want the button to hide/restore the series, you can remove this code if you want that only your custom action is triggered.
entry = legendBox.addElement(UIElementBuilders.CheckBox)
entry.onSwitch((_, checked) => {
console.log('clicked', checked)
})
See also UIElementBuilders.ButtonBox if you want to add automatic bounce-back.
entry = legendBox.addElement(UIElementBuilders.ButtonBox)
entry.onSwitch((_, checked) => {
if (checked) {
console.log('button pressed')
}
})

How to hide or disable the "Add Row" right to the IG when the first row is added oracle apex

I am trying to hide or disable the "Add Row" button right to the IG (Intractive Grid) when the first row is added in Grid.
Only one record should be available in the IG, so once the first is inserted automatically the "Add Row" Button should be hidden or disabled.
I have tried in Js but it’s hiding the button once the page loads.
function(config) {
var i, toolbarData = apex.jQuery.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3");
// find and remove the add_row button
for (i = 0; i < toolbarGroup.controls.length; i++ ) {
if ( toolbarGroup.controls[i].action === "selection-add-row" ) //for save and edit it is working
{
toolbarGroup.controls.splice(i,4);
break;
}
}
config.toolbarData = toolbarData;
return config;
}
Looks like a vary complicated procedure for a simple task
possible solutions:
If all you need is adding one row - use a form instead of IG
Initiate the region with one empty line, and remove the "Add row" button all in all
Use a dynamic action which is triggered by the Add row button that disables the same button

Select one cell and by clicking a button change value of a different cell

I want to insert a button into my google spreadsheet, that, when clicked, copies the content of the selected cell to another cell. Is there any way to do this?
I tried googling for a solution myself, but I'm overwhelmed by all sorts of different scripts/macros/addons that are available.
Would be amazing if you could help me out on this one.
you will need a script for this purpose like:
function moveValuesOnly1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();
var currentCell = selection.getCurrentCell();
source.copyTo(ss.getRange("Sheet2!B1"), {contentsOnly: true}); }
which copies selected cell from selected sheet into B1 cell of Sheet2
and then just go Insert > Drawings and create a button. when done link the script with button and you are done.

dojo enhanced datagrid loses focus after edit

I have an enhanced datagrid that uses a jsonreststore.
I have set the editable cell to auto-save. To do this, I added a onApplyCellEdit property. after successful save (by pressing enter key) the server responds with the new data and my datagrid is updated. however, the focus on the cell just edited loses focus. As a result I cannot use the arrow key to navigate to the next cell, forcing me to use the mouse. Is there any way to regain focus so that I can use the keyboard to navigate after editing?
I have done following code to kind of regain the focus using setTimeout but I think it is not a good solution because if it takes too long for the server to respond the cell will regain focus first and when the response comes in and cell is updated, the cell will lose focus:
var accounts = new EnhancedGrid({
structure: account_layout,
selectionMode: "single",
canSort: function(){
return false
},
onApplyCellEdit: function(inValue,inRowIndex,inFieldIndex){
if(this.store){
this.store.save();
window.setTimeout(function(){
var cells = accounts.layout.cells;
var fieldLocation;
for(var i = 0; i < cells.length; i++){
if(inFieldIndex === cells[i].field){
fieldLocation = i;
break;
}
}
accounts.focus.setFocusCell(cells[fieldLocation],inRowIndex);
},500);
}
}
});
I also tried:
this.store.save().then(function(){ ...});
But it's not working.
EDIT
To clarify question, I added sentence after first sentence of 2nd paragraph.

Anguilla - Updating a field's value from a popup?

I have a modal popup that appears whenever an editor tries to save a component with some values (a date field in the past in this case).
In this popup I show the editor a few options (very similar to the default "Open Shared Item" dialog) and an OK/Cancel button combo. On Cancel I fire the "cancel" event and the editor goes back to the editing screen, all good here. On "OK" I want to change the value of the field to match whatever the editor selected, then save.
I tried to use an approach with FieldBuilder and the sample Boris mentioned on this other topic but I can't get to the field from my popup dialog.
Any suggestions on how I can go and modify the xml of the item (could be also a page) from a modal popup?
EDIT: Code used in getControlForFieldName
function getControlForFieldName(name) {
var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
var fieldsContainer = fieldBuilder.properties.input;
var fieldsNode = fieldsContainer.getElement();
var fieldContainer = $dom.getFirstElementChild(fieldsNode);
while (fieldContainer) {
var labelNode = $dom.getFirstElementChild(fieldContainer);
var fieldNode = $dom.getNextElementSibling(labelNode);
var control = fieldNode.control;
if (control.getFieldName() == name) {
return control;
}
fieldContainer = $dom.getNextElementSibling(fieldContainer);
}
}
EDIT #2
After Frank's advice, and some help from Jaime & Frank offline, I got it to work as follows:
The popup is called from a Command Extension (Save & Close in my case)
The command.js specifies an event handler that gets called on "submit" (== OK was pressed)
$evt.addEventHandler(p.dialogPopup, "submit",
this.getDelegate(this._onPopupSubmit));
In my popup I am passing the selected item (it's a keyword ID) to the event handler:
this.fireEvent("submit", { id: select.options[select.selectedIndex].value });
and now back in the event handler _onPopupSubmit(e) I just read e.data.id, load this keyword, get properties like ID & Title, and update the metadata of the item using item.setMetadata("new metadata with updated values").
Simple :)
Your code runs in a popup, so any references you make to global variables will be taken from the popup window.
So when you get the fieldBuilder:
var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
$display is a reference to a global variable. So this actually looks for the FieldBuilder in the popup window (which doesn't have one).
To get the FieldBuilder of the Component window, you can get it from the opener:
var fieldBuilder = opener.$display.getView().properties.controls.fieldBuilder;
You might want to consider actually passing the updated value to either a callback function or with a (custom) event though, since that makes your popup less dependent on opener. trick.

Resources