doabit / semantic-ui-sass

Semantic UI, converted to Sass and ready to drop into Rails & Compass.
MIT License
1.15k stars 192 forks source link

Form submit with dropdown doesn't pass params to the server #82

Closed andrey-lizunov closed 8 years ago

andrey-lizunov commented 8 years ago

I have form with semantic-ui dropdown with these classes "ui fluid search dropdown selection multiple" and the problem, that form submit doesn't pass params from this dropdown to my server. But dropdowns without "multiple" param works fine in same case. I make submit on "onAdd"


$('@locations').dropdown(
   onAdd: (addedValue, addedText, $addedChoice) ->
      $('@searchPanelForm').submit()
   )
)
doabit commented 8 years ago

@andrey-lizunov If you use https://github.com/Semantic-Org/Semantic-UI not with the gem, it works?

andrey-lizunov commented 8 years ago

@doabit It looks like submit doesn't pass params only if I trigger this event on form in "onAdd" callback

If you use https://github.com/Semantic-Org/Semantic-UI not with the gem, it works?

Will check it right now.

andrey-lizunov commented 8 years ago

@doabit Here is small example https://jsfiddle.net/andreylizunov/5bbum10m/15/

doabit commented 8 years ago

@andrey-lizunov Hi, if you want to upload file with ajax in rails, you must use https://github.com/JangoSteve/remotipart or https://github.com/malsup/form.

andrey-lizunov commented 8 years ago

@doabit I don't try to upload files, it's simple select with options. And for some reasons, submit on form in "onAdd" callback don't pass params from this semantic-ui multiple select. I don't have same problem with non multiple selects, when I trigger submit on form in "onChange" callback. And yes, I use Rails and form has remote: true parameter.

doabit commented 8 years ago

@andrey-lizunov Sorry, my mistake, I've tested and it works

<form id="test_form" action="/test" data-remote="true" method="get">
  <select name="locations[]" id="locations" class="ui fluid search dropdown" multiple="">
    <option value="9961">Russia, Tver</option>
    <option value="9483">Russia, Moscow</option>
    <option value="9440">Russia, Saint Petersburg</option>
  </select>

</form>

<script type="text/javascript">
  $(function(){
    $('#locations').dropdown({
        onAdd: function(value) {
          console.log(value)
          $("#test_form").submit()
        }
      }
    )
  })
</script>
   42: def test
 => 43:   binding.pry
    44: end

[1] pry(#<PostsController>)> params
=> <ActionController::Parameters {"locations"=>["9961", "9483"], "controller"=>"posts", "action"=>"test"} permitted: false>
andrey-lizunov commented 8 years ago

@doabit Hm, strange, because I still have empty params in same case(( But anyway, maybe it because of some my mistake in code. And I find another way, wich works in my case, it's handle the "change" event on select and trigger submit from there. Thx for your help, Sean!

doabit commented 8 years ago

@andrey-lizunov You're welcome.