Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm new to Rails and Netzke, but this is how I would solve the problem.</p> <p>First, if Type3 depends on Type1 and Type2, then only Type3 should be referenced in Plant. </p> <p>So, instead of</p> <pre><code>rails g model plant type1:references type2:references type3:references name:string </code></pre> <p>use</p> <pre><code>rails g model plant type3:references name:string </code></pre> <p>You can always reference type1 and type2 by using Netzke's <code>__</code> (double underline) notation. This is my version of Plants grid. I do not allow inline editing, except for most trivial models.</p> <pre><code>class Plants &lt; Netzke::Basepack::Grid def configure(c) super c.model = 'Plant' c.persistence = true c.columns = [ { name: :type3__type1__name, header: 'Type 1'}, { name: :type3__type2__name, header: 'Type 2'}, { name: :type3__name, header: 'Type 3'}, { name: :name, header: 'Plant Name' } ] c.enable_edit_inline = false c.enable_add_inline = false end def preconfigure_record_window(c) super c.form_config.klass = PlantForm end end </code></pre> <p>To connect the combo boxes you need to:</p> <ol> <li><p>Define scope for type3 combo so that its data depends on type1 and type2 IDs.</p> <pre><code>#Example scope definition scope: {type1_id: component_session[:type1_id], type2_id: component_session[:type2_id]} </code></pre></li> <li><p>Define listeners for type1 and type2 combos (see <code>js_configure</code> method). Listeners will detect any change in type1 and type2 and prepare type3 to refresh its data next time it gets selected.</p></li> <li><p>Endpoints and session variables are used for IDs exchange.</p> <pre><code>//JavaScript code //Definition of listener function for type1 combo var handleType1Change = function() { //Type3 value is no longer valid type3Combo.clearValue(); //Setting lastQuer to null will force data refresh for type3 combo //next time it gets selected. type3Combo.lastQuery = null; //Call endpoint to define session variable with ID of type1 combo this.selectType1({type1_id: type1Combo.value}); }; #Ruby code #The endpoint is called from handleType1Chnage listener to #set session variable with selected ID in type1 combo. endpoint :select_type1 do |params, this| component_session[:type1_id] = params[:type1_id] end </code></pre></li> </ol> <p>This is my complete code for Plant form:</p> <pre><code>class PlantForm&lt; Netzke::Basepack::Form def configure(c) super c.model = 'Plant' c.title = 'Plant' c.items = [ { field_label: 'Type1', xtype: :combo, store: Type1.select([:id, :name]).map { |x| [x.id, x.name] }, id: 'type1Combo', #Sets the value for type1 in case change form is opened value: record &amp;&amp; record.id ? record.type3.type1_id : nil }, { field_label: 'Type2', xtype: :combo, store: Type2.select([:id, :name]).map { |x| [x.id, x.name] }, id: 'type2Combo', #Sets the value for type2 in case change form is opened value: record &amp;&amp; record.id ? record.type3.type2_id : nil }, { field_label: 'Type3', name: :type3__name, id: 'type3Combo', data_store: {auto_load: false}, scope: {type1_id: component_session[:type1_id], type2_id: component_session[:type2_id]} }, { field_label: 'Name', name: :name } ] end js_configure do |c| c.init_component = &lt;&lt;-JS function() { this.callParent(); var type1Combo = this.getComponent('type1Combo'); var type2Combo = this.getComponent('type2Combo'); var type3Combo = this.getComponent('type3Combo'); var handleType1Change = function() { type3Combo.clearValue(); type3Combo.lastQuery = null; //force data refresh in type3 combo this.selectType1({type1_id: type1Combo.value}); }; var handleType2Change = function() { type3Combo.clearValue(); type3Combo.lastQuery = null; this.selectType2({type2_id: type2Combo.value}); }; type1Combo.addListener('select', handleType1Change, this); type2Combo.addListener('select', handleType2Change, this); } JS end endpoint :select_type1 do |params, this| component_session[:type1_id] = params[:type1_id] end endpoint :select_type2 do |params, this| component_session[:type2_id] = params[:type2_id] end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload