ChoicesRestful
Configures access to a RESTful service that returns choices for Checkbox, Dropdown, Radiogroup, and other multiple-choice question types.
Use the following properties to configure this object:
{
url: "http://...", // A RESTful service's URL.
valueName: "value", // Specifies which field contains choice values.
titleName: "title", // Specifies which field contains display texts for choice values.
imageLinkName: "imageUrl", // Specifies which field contains image URLs. Used in Image Picker questions.
// Path to the array of choices. Specify `path` only if the array of choices is nested within the object returned by the service.
// The following path separators are allowed: semicolon `;`, comma `,`.
path: "myNestedArray"
}
Typically, you should assign this object to a question's choicesByUrl
property.
Inherited from the following class(es):
Methods
Creates a new object that has the same type and properties as the current SurveyJS object.
- Type:
- () => Base
- Implemented in:
- Base
Assigns a new configuration to the current SurveyJS object. This configuration is taken from a passed JSON object.
The JSON object should contain only serializable properties of this SurveyJS object. Event handlers and properties that do not belong to the SurveyJS object are ignored.
- Type:
- (json: any) => void
- Parameters:
-
json, type: any ,
A JSON object with properties that you want to apply to the current SurveyJS object.
- Implemented in:
- Base
- See also:
- toJSON
Returns a JsonObjectProperty
object with metadata about a serializable property that belongs to the current SurveyJS object.
If the property is not found, this method returns null
.
- Type:
- (propName: string) => JsonObjectProperty
- Parameters:
-
propName, type: string ,
A property name.
- Implemented in:
- Base
Returns the value of a property with a specified name.
If the property is not found or does not have a value, this method returns either undefined
, defaultValue
specified in the property configuration, or a value passed as the defaultValue
parameter.
- Type:
- (name: string, defaultValue?: any) => any
- Parameters:
-
name, type: string ,
A property name.
defaultValue, type: any ,(Optional) A value to return if the property is not found or does not have a value.
- Implemented in:
- Base
Specifies which property in the obtained data object contains image URLs. Used only in Image Picker questions.
- Type:
- string writable
This property is stored in the survey JSON definition and can be edited in the Survey Creator.
- Implemented in:
- ChoicesRestful
Returns true
if the object is included in a survey.
This property may return false
, for example, when you create a survey model dynamically.
- Type:
- boolean readonly
- Implemented in:
- Base
Returns true
if the survey is being designed in Survey Creator.
- Type:
- boolean readonly
- Implemented in:
- Base
Returns true
if the object configuration is being loaded from JSON.
- Type:
- boolean readonly
- Implemented in:
- Base
Returns true
if a passed value
is an empty string, array, or object or if it equals to undefined
or null
.
- Type:
- (value: any, trimString?: boolean) => boolean
- Parameters:
-
value, type: any ,
A value to be checked.
trimString, type: boolean ,(Optional) When this parameter is
true
, the method ignores whitespace characters at the beginning and end of a string value. Passfalse
to disable this functionality.
- Implemented in:
- Base
An event that is raised when an ItemValue
property is changed.
Parameters:
sender
:this
A SurveyJS object whose property contains an array ofItemValue
objects.options.obj
:ItemValue
AnItemValue
object.options.propertyName
:String
The name of the property to which an array ofItemValue
objects is assigned (for example,"choices"
or"rows"
).options.name
:"text"
|"value"
The name of the changed property.options.newValue
:any
A new value for the property.
- Type:
- Event<(sender: Base, options: any) => any, Base, any>
- Implemented in:
- Base
An event that is raised when a property of this SurveyJS object has changed.
Parameters:
sender
:this
A SurveyJS object whose property has changed.options.name
:String
The name of the changed property.options.newValue
:any
A new value for the property.options.oldValue
:any
An old value of the property. If the property is an array,oldValue
contains the same array asnewValue
does.
- Type:
- EventBase<Base, any>
- Implemented in:
- Base
Path to the array of choices. The following path separators are allowed: semicolon ;
, comma ,
.
Specify this property only if the array of choices is nested within the object returned by the service. For example, the service returns the following object:
{
countries: [ ... ],
capitals: [ ... ]
}
To populate choices with values from the countries
array, set the path
property to "countries"
. To use the capitals
array, set this property to "capitals"
.
- Type:
- string writable
This property is stored in the survey JSON definition and can be edited in the Survey Creator.
- Implemented in:
- ChoicesRestful
- See also:
- url * , valueName * , titleName
Registers a function to call when a property value changes.
- Type:
- (propertyNames: string[], handler: any, key?: string) => void
- Parameters:
-
propertyNames, type: string[] ,
An array of one or multiple property names.
handler, type: any ,A function to call when one of the listed properties change.
key, type: string ,(Optional) A key that identifies the current registration. If a function for one of the properties is already registered with the same key, the function will be overwritten. You can also use the key to subsequently unregister handlers.
- Implemented in:
- Base
- See also:
- unregisterPropertyChangedHandlers
Assigns a new value to a specified property.
- Type:
- (name: string, val: any) => void
- Parameters:
-
name, type: string ,
A property name.
val, type: any ,A new value for the property.
- Implemented in:
- Base
Specifies which property in the obtained data object contains display texts for choices.
- Type:
- string writable
This property is stored in the survey JSON definition and can be edited in the Survey Creator.
- Implemented in:
- ChoicesRestful
Unregisters value change event handlers for the specified properties.
- Type:
- (propertyNames: string[], key?: string) => void
- Parameters:
-
propertyNames, type: string[] ,
An array of one or multiple property names.
key, type: string ,(Optional) A key of the registration that you want to cancel.
- Implemented in:
- Base
- See also:
- registerPropertyChangedHandlers
A RESTful service's URL.
This property supports dynamic URLs. For example, the URL below depends on the region
question's value. When the value changes, the survey automatically loads a new dataset that corresponds to the selected region.
url: "https://surveyjs.io/api/CountriesExample?region={region}"
- Type:
- string writable
This property is stored in the survey JSON definition and can be edited in the Survey Creator.
- Implemented in:
- ChoicesRestful
- See also:
- path * , valueName * , titleName
Copyright © 2023 Devsoft Baltic OÜ. All rights reserved.