Class: Mxrb::Compiler::ComboBoxBundleCompiler

Inherits:
Object
  • Object
show all
Includes:
ModelValues
Defined in:
lib/mxrb/compiler/combo_box_bundle_compiler.rb

Overview

Compiles association- and database-backed instances of the official React Combo box widget. rubocop:disable Metrics

Constant Summary collapse

WIDGET_ID =
'com.mendix.widget.web.combobox.Combobox'

Instance Method Summary collapse

Constructor Details

#initialize(source, page_name, widget, scope:, entity:) ⇒ ComboBoxBundleCompiler

Returns a new instance of ComboBoxBundleCompiler.



15
16
17
18
19
20
21
22
23
24
# File 'lib/mxrb/compiler/combo_box_bundle_compiler.rb', line 15

def initialize(source, page_name, widget, scope:, entity:)
  @source = source
  @page_name = page_name
  @widget = widget
  @scope = scope
  @entity = entity
  @index = document_index
  @values = property_values(widget['Object'])
  @data_source = WebListDataSource.new(source, widget)
end

Instance Method Details

#renderObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mxrb/compiler/combo_box_bundle_compiler.rb', line 30

def render # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  properties = primitive_properties.merge(
    key: widget_key, '$widgetId': widget_key, class: css_class, id: widget_key,
    optionsSourceStaticDataSource: [],
    ariaRequired: raw(expression(false))
  )
  properties.merge!(source_properties)
  control = "React.createElement($Combobox, #{javascript(properties)})"
  caption = translated_text(@widget['LabelTemplate'])
  group = {
    key: "#{widget_key}$formGroup", '$widgetId': "#{widget_key}$formGroup",
    class: "#{css_class} mx-combobox", control: raw("[#{control}]"),
    width: 3, orientation: 'horizontal', labelFor: widget_key,
    caption: raw(expression(caption)), hasError: raw(expression(false))
  }
  "React.createElement($FormGroup, #{javascript(group)})"
end

#supported?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mxrb/compiler/combo_box_bundle_compiler.rb', line 26

def supported?
  widget_type&.fetch('WidgetId', nil) == WIDGET_ID && supported_source? && resolved_scope
end