Get a selected value from a slate code sandbox - palantir-foundry

I'm trying to make a dropdown list with the code sandbox in the palantir slate, but I can't capture the selected value of the button in a function like the existing dropdown button, is there any way to capture this value with the code sandbox?
This is my code sandbox button
I am trying to capture the selected button value from this function tab
I am new to stack overflow, if you need more information just let me know, I am grateful to everyone who has offered to help me.
I tried to capture the value with selectedValues but apparently this option does not exist. I also tried with javascript for "document.getElementById("standard-select");"
but the console always returns undefined.

You want to get a value from the Code Sandbox to the Slate context.
You can follow this : https://www.palantir.com/docs/foundry/slate/widgets-advanced/#setstate
In short, You need to use the state of the Code Sandbox widget :
In the "Interaction" tab of the Code Sandbox, you need to specify an arbitrary state's variable, for instance : {"dropdownValue": "default_value"}
In your custom JS in Code Sandbox, you will store the value of interest (the value of your dropdown, for instance whenever it changes) in the state of the Code sandbox SlateFunctions.setState("dropdownValue", 4)
In your Slate's function, you can access the Code Sandbox state as any other variable : return {{w_mycodesandbox.state.dropdownValue}}
Whenever you call setState from your custom JS, you update the state, hence the variable the Slate function depends on, and dependencies will run as expected.

We can get a selected value from a Slate code sandbox by using the getSelectedValue() method. This method returns an object containing the currently selected value from the Slate code sandbox. The object contains the value, type, and range for the selection.

Related

How can I run a Foundry Function on Object only when clicking a button in Slate

I am using Slate, and running a Foundry Function on Object (FoO) based on input from users of the application. However, anytime a user changes one of the input, the function re-runs, which seems inefficient.
Is there a way to run the Function only when a user clicks a specific button? I have tried using the conditional triggers, but the function still runs anytime a text field changes.
Slate is pretty powerful, and we can leverage the event system to do this properly. As we noticed, the function runs any time a change happens to one of its input. So we have to control when those changes happen. The way to do is is to have the following logical sequence of events:
Create a new variable (defaults to undefined is fine)
An event, fired when we click the button, computes the expected input of our Foundry Function from the input fields, and sets the variable.
The function input is the content of this variable - the function will only run when the variable changes (so, when we click the button)
This creates a sort of "gap" between the input fields and the function itself - the function will only run when the button is clicked.
In practice, this looks like this -
General setup of the application
Create an empty variable, and add an event computing the expected input of your function when clicking the button
Make sure that your function is using the variable as an input

Is it possible to change the title property of an object via a derived value from an edit form in Foundry?

I created an object that is backed by a Foundry Form and I would like to provide a user to change the properties of that object. I linked the form to the object and created a title property that is a hidden/ derived value in the object creation form. A user can edit property a and property b and the title of the object will be ab.
When the user updates the object in the edit form the title does not update. Is there a configuration I need to change?
Yes, this is possible. There's actually two ways to achieve this, I'll list them in order of my preference:
Using an action
The modern way of achieving this is to use an action. Actions allow you to flexibly "intercept" events like writes from users and do extra actions (hence the name) or prevent things from happening. They are a fairly new feature in foundry.
The basic concept is that you write a little piece of code (a function on an object) that gets executed when the object is modified. The function can then modify the object further or prevent the modification.
This is very flexible, because it will allow you to automatically update the title of the object regardless of how and when the object was edited. You can also apply more complex logic to derive the title from e.g. multiple properties with fallbacks, or modify a property in a certain way before you put it into the title, et cetera.
The drawback is that this requires you to write some code.
On your stack, if you navigate to https://www.palantir.com/docs/foundry/functions/use-functions/#actions you will find an introduction on how to get started with actions. The example solves the exact use-case you're asking for.
Using form templates
Another approach that's simpler and does not require writing any code, but is much less flexible, is to use a template in the form. You can create a template form widget that's invisible, and is automatically populated by values from other form fields.
The advantage is that this is very easy and quick to set up, but the disadvantage is that it will only apply when the object is edited through the form, and you can really only do concatenation, not much else.
It sounds like this is what you attempted to do, and I believe this should work. If it doesn't, I would check the following things:
make the template visible to see that it gets filled out like you expect it to
make sure the template is set to store its response into the right property on the object
make sure the user is using the form to edit the object, not some other way (like editing the property directly in hubble)

Design time slider

I wish to add this design as a time slider in my dashboard.
Has anyone ever designed this using React, HTML? Any help is appreciated.
If those circles, lines are based on your returned json data, it is quite straightforward with React / Redux. You can follow the steps:
You need to add event listeners on your timeline either click or mouseover
Define the state variable mapData in the constructor
trigger the event and retrieve different data via http request
make sure you call setState() with the new data and bind them into your state variables
Bind the state variable into the render() elements and you will see the change.
Hopefully it can help you out.

Dispatching actions before rendering component

I'm using redux and es6. I want to dispatch an action before components will mount. The problem is that with redux newest syntaxis componentWillMount doesn't exists any more. So... where should i dispatch this action.
My case: I have a component that needs user's info (such as name, for example). I need to get the user's name before that component mounts.
thanks,
Connect your component to a field in your state, let's call it "name". When the component renders, make sure it checks if name is not empty; if it is then it renders it, if not then it renders nothing.
In the componentDidMount, fire your dispatch as normal - this in turn will reduce and end up changing the value of "name" in your state. This will cause a re-render and will then show properly.
componentWillMount only exists server side, so it is usually not the best idea to dispatch actions from it, as if you just had your client side code, they wouldn't work.

Mvvmcross, how to access a ViewModel from my android project

I have an Android app which uses a SupportActionBar that contains a bunch of tabs. These tabs each have a fragment that in turn are connected to a ViewModel in my core project. This works great and when i start the app they are all initialized right away and setup correctly.
What i would like to do is to call on a method on one of these ViewModels from my main activity that contains all the tabs and fragments.
I read in another post that in WP you could cast the DataContext to the ViewModel but that might not work in Android. I haven't been able to do this, maybe because my DataContext is not the currently displayed ViewModel but the MainViewModel connected to my main activity. Or maybe it's not supposed to be done that way, i'm not sure.
I'm trying to do this:
var test = (MessagesViewModel)this.DataContext;
test.GetViewDataFromApi();
To update the data in the view when i press the tab. I can't use the Init function for this for example since the ViewModel isn't recreated everytime i show the view.
Are you trying to update some data in the tab's fragment when tab is selected?
If that's the case, one way to do it is to
1) handle the tab selection event to get the current tab(maybe using TabListener),
2) get the fragment (MvxFagment) in the selected tab
3) get the (IMvxViewModel) view-model from the fragment
4) call the method you need to update data on the view-model
I assume you are using a MvxFragment (https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Droid.Fragging/Fragments/MvxFragment.cs?source=cc) so you can access the view-model from the MvxFragment's ViewModel property.