Ruby on Rails #81 StimulusJS: Conditionally display form fields based on selected value

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 16

  • @SupeRails
    @SupeRails  2 года назад +12

    Do you want more episodes on writing and applying StimulusJS controllers?

    • @merdandurdiyev7408
      @merdandurdiyev7408 4 месяца назад

      Definitely. I'd like to have more about Stimulus JS controllers. Your videos set things on fire, go on SupeRails !!!

  • @eayurt
    @eayurt 2 месяца назад

    That one was super helpful man. Thank you

  • @juliakanzaki
    @juliakanzaki 6 месяцев назад

    thanks for the video, its reeeeally helpful

  • @DavidNijman
    @DavidNijman Год назад +3

    else if (this.inputTarget.value = this.showIfValue)
    Not == ?

    • @rahulk6130
      @rahulk6130 Год назад

      I was wondering about that too. I thought he would put a ternary condition, or just use the condition to set the value.

  • @time2growWithHetal
    @time2growWithHetal 2 года назад +2

    Yes sure . It will be very helpful. Your videos are awesome

  • @rahulk6130
    @rahulk6130 Год назад

    Excellent video. I am wondering if this approach will work if I have to show different fields based on the first field. I am referring to the Agile Rails book in which, based on payment type, you get different fields. That was implemented using react. Do you think this approach will work for that too?

  • @MatthewKennedyUK
    @MatthewKennedyUK 2 года назад +1

    This is a good solution for a very simple form, but it will brake down when you add a required html attribute to that passcode field, once hidden it will block the submit, unless you also toggle the required attribute.
    Also you might want to be careful if you select passcode protected, add some value, then switch back to the other option and submit, you could drag through any value still present in the now hidden passcode field.

    • @SupeRails
      @SupeRails  2 года назад +1

      Hello Mathew!
      Condiderin a hidden passcode field -> in a real app I think that I would do something like this:
      # app/models/post.rb:
      ```
      before_create do
      unless passcode_protected?
      passcode: nil
      end
      end
      ```

    • @MatthewKennedyUK
      @MatthewKennedyUK 2 года назад

      @@SupeRails Good videos by the way, it is very interesting to see how people approach different problems like this.
      I'm dealing with a country selector that, depending on the country chosen might require a zip code and/or a state.

    • @SupeRails
      @SupeRails  2 года назад +1

      @@MatthewKennedyUK Country->State->City select episode coming this Thursday (in 2 days) :)
      [The technology is same as #80, but with some nice validations]

  • @mdezh
    @mdezh Год назад

    Интересно, но в 14й строке контроллера стоит не проверка на равенство, а присвоение (работает, потому что там всегда true). Да и вообще там условие не нужно, можно было просто else обойтись. Ну и в принципе можно было написать в одну строчку без if: this.outputTarget.hidden = this.inputTarget.value != this.showIfValue
    Но вообще, спасибо за видео, я рельсами недавно занялся, благодаря вам узнаю много интересного и полезного.

  • @rodolphedesbois2658
    @rodolphedesbois2658 Год назад

    Very nice video... how to do with a boolean selector ? I'm searching everywhere and nothing...

    • @tombranson9341
      @tombranson9341 Год назад

      question is not clear, but if you mean a boolen type as the values field, then it's declared like static values = { myValue: Boolean }.

  • @eayurt
    @eayurt 2 месяца назад

    Thanks!