Dev Space

Customize & extend the power of Alteryx. SDKs, APIs, custom tools, and more!
SOLVED

HTML SDK - How to set the NumericSpinner default value?

Highlighted
Fireball

My custom tool requires a numeric input for which I'd like to use a NumericSpinner UI element. It worked just fine with the ConstrainedInt Data Item, and I'm using a min, max, and step values to control the user interaction nicely.

 

However, I can't seem to see how to set the default value. The NumericSpinner API documentation shows only the tabIndex is configurable. The HTML GUI SDK Supported Data Items documentation says that ConstrainedInt has a default value of zero (depending on min and max values it appears), but that we can register a 'listener' for the 'value' property. However, the ConstrainedInt API documentation does not show 'value' as part of the constructor or expose set/get for this property.

 

I can see the 'value' using the CEF debug tool, but this is 'too late' as the tool has already run to create the HTML interface. I need to set the default 'value' in the 'BeforeLoad' javascript function.

 

Is there a way to do this? Would I have to set the min to my default value, then run an AfterLoad function to set the min back to the true min?

Highlighted

@c2willis  Does @NeilR 's post to this challenge help? Here was his comment, note the script piece at the end.

<div class="widgetLabel">Z</div>
<ayx data-ui-props='{type:"NumericSpinner", widgetId:"z_spinner"}' data-item-props='{dataName:"z_spinner", dataType:"SimpleFloat", value:"1"}'></ayx>

<div class="widgetLabel">Field to test</div>
<ayx data-ui-props='{type:"DropDown", widgetId:"field_dropDown"}' data-item-props='{dataName:"field_dropDown", dataType:"FieldSelector"}'></ayx>

<script>
  Alteryx.Gui.BeforeLoad = function (manager, AlteryxDataItems, json) {
    manager.getDataItem('z_spinner').setValue(3)
  }
</script> 

 

Highlighted
Fireball

@patrick_digan- Yes, yes it does! Thanks for the quick reply!

 

This was one of those issues that I should have just pressed on a little bit more ... because as soon as I posted my question, I switched over to the Console tab of the CEF I found the 'getDataItem()' of the manager and saw that I could invoke the setValue() method from there.

 

My final solution that work is below, where the 'LogicalRecordLength' string was the name of the new AlteryxDataItems.ConstrainedInt():

 

manager.getDataItem('LogicalRecordLength').setValue(47)