class HashInput

Public Instance Methods

render() click to toggle source
# File lib/bull/ui_core.rb, line 394
def render
  span do
    input(placeholder: 'key', value: state.key).on(:change){|event| state.key! event.target.value}
    input(placeholder: 'value',value: state.value).on(:change){|event| state.value! event.target.value}
    button{'add'}.on(:click) do
      hsh = params.value.dup
      hsh[state.key] = state.value
      params.on_change.call hsh
      state.key! ''
      state.value! ''
    end
    table do
      tr do
        th{'key'}
        th{'value'}
        th{' '}
      end
      params.value.each_pair do |k, v|
        tr do
          td{k}
          td{v}
          td{i(class: 'fa fa-times')}.on(:click) do
            hsh = params.value.dup
            hsh.delete k
            params.on_change.call hsh
          end
        end
      end
    end
  end
end