Helmut
Joined 8/12/2020
Helmut said almost 4 years ago on Autocomplete with StimulusJS :
Hi David, thanks for the quick reply! I will triple-check things tomorrow and post code, but can say that I see no errors in the Terminal log, and I put a "PUTS "THE INDEX IS BEING CALLED!!!" message into my Client controller Index action, and it never appears (in my bigger project, I have Invoices that belong to Clients, instead of Books that belong to Authors).

But one question: you say "In the initialize() function, you could put a console.log within there to make sure that it is getting triggered". But where would I find the actual controllers that Stimulus-Autocomplete installs? There are no autocomplete controllers in my Javascript>Controllers folder (where all my other stimulus controllers are), and I figured that the Autocomplete controllers were not accessible because I installed them via Yarn. I know Stimulus is generally working in my app because lots of other parts of the app use it (including your Nested_Forms controller, which has been great!). 

Thanks!

Helmut said almost 4 years ago on Autocomplete with StimulusJS :
Hi David, okay, I didn't realize I could just put some Javascript in Index.js. So I put a console.log statement in there, but it doesn't show up when I run my problem app. However, on my smaller sample app that mimics your demo, I can put that same console.log statement in the Index.js file, and it DOES show up. 

So I think the Autocomplete installation just isn't working on my bigger app, since the code between my sample app and bigger app is pretty much identical except for a couple of different class names (Invoice for Book, Client for Author).  Do you know if there's a way to uninstall Autocomplete, and maybe start again? Or take other steps to troubleshoot why Rails (6.0.3) isn't seeing the library? 

Thank you!

Helmut said almost 4 years ago on Autocomplete with StimulusJS :
David, I got it working! 

I removed the Yarn install of autocomplete, and then installed again. Nothing. Finally, I came across the "application.js" file in a "javascript/packs" folder and noticed that it had some of the same lines as the index.js file. I had used this file to install Tailwind and Flatpickr a couple months ago, but that was about it, and I forgot about it. But it occurred to me that index.js is being ignored because application.js  is doing all that stuff already. So I just moved the "import Autocomplete" and "application.register" lines into my application.js file, and everything worked....

Whew! 

Thanks for the assistance, though, it's appreciated....





Helmut said over 3 years ago on Hotwire :
I also had the problem where my app was not reseting the form...determined that the Stimulus controller (reset_form_controller.js) was not working properly. The reset action simply wouldn't do anything (like a console log). This is not the first time a new Stimulus controller has not functioned properly, by the way!

So I just moved the reset action into the Stimulus demo controller called "hello_controller.js" that comes with a new Rails install, and then called that from the my HTML. That worked.   

Here's the hello_controller.js....
import { Controller } from "stimulus"

export default class extends Controller {
  static targets = ["button"]


  reset() {
    console.log("IM IN THE RESET ACTION!!!!!");
    this.element.reset();
    this.buttonTarget.disabled = false;
  }

}



And here's the HTML for the form...
<%= form_with model: List.new, data: {controller: 'hello', action: 'turbo:submit-end->hello#reset'} do |form| %>
  <div class="field">
    <%= form.label :name %>
    <%= form.text_field :name %>
  </div>
  <div class="actions">
    <%= form.submit 'Post', 'data-hello-target': 'button'%>
  </div>
<% end %>


Helmut said over 2 years ago on Drag and Drop with Hotwire :
Hi! Coming to this a little late! I have the drag and drop working on screen, but I'm not able to successfully achieve the PUT on a path so the drag/drop actions becomes permanent (ie, gets to my controller which will record all the relevant position values).

I keep getting this error:
Started PUT "/industries" for ::1 at 2022-08-02 17:43:22 -0700
ActionController::RoutingError (No route matches [PUT] "/industries"):

But I  certainly have an /industries route. I've also tried to connect to ANY route I have but nothing works. Any idea what's going on? 

Here's the relevant code, I've double-checked it and don't think anything is wrong with it. Thanks!

  async updatePosition(event) {
    const response = await put('/industries', {
      body: JSON.stringify({
        sgid: event.item.dataset.sgid,
        position: event.newIndex + 1
      })
    })
    if (response.ok) {
      console.log(event.item.dataset.sgid)
    }
  }