Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add outlets to nested folders #672

Closed
pqvel opened this issue Apr 16, 2023 · 2 comments · Fixed by #696
Closed

how to add outlets to nested folders #672

pqvel opened this issue Apr 16, 2023 · 2 comments · Fixed by #696

Comments

@pqvel
Copy link

pqvel commented Apr 16, 2023

i have 2 controllers which are on the path controllers/create_controller.js and controllers/app/todos_controller.js. How can I add outlet todos for the create controller?
my HTML:
image

create_controller.js:
`import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["todoText"]
static outlets = ["todos"]

createTodo(e) {
e.preventDefault()
this.todosOutlet.addTodo(this.todoTextTarget.value)
this.todoTextTarget.value = ""
}
}
_app/todos_controller.js:_import { Controller } from "@hotwired/stimulus"
import { v4 as uuid } from 'uuid'

export default class extends Controller {
static targets = ["todos"]
static values = { todos: Array }

initialize() {
this.todos = []
}

addTodo(todo) {
this.todos.push({
todo,
id: uuid(),
active: false
})
this.renderTodos()
}

renderTodos() {
let todos = ''
this.todos.forEach(todo => {
todos += <li class="${todo.active ? 'active' : ''}"> <p>${todo.todo}</p> <input data-action="todos#changeActiveTodo" data-todos-id-param="${todo.id}" type="checkbox" value="${todo.active}" > </li>
})
this.todosTarget.innerHTML = todos
}
}
`

@adiakritos
Copy link

I am also wondering the same thing.

<div class="leads--foo" data-controller="leads--foo"></div>
<div data-controller="leads--table-filter" data-leads--table-filter-leads--foo-outlet=".leads--foo"></div>

// TABLE FILTER CONTROLLER

  static outlets = [ 'leadsFoo' ]

  connect(){
    console.log('table filter controller connected');
    console.log(this.hasLeadsFooOutlet);
    this.submitFormWhenDatePickerChanges()
    this.timeout = null;
  }            


// FOO CONTROLLER

export default class extends Controller {
  connect() {
    console.log('leads foo controller connected');
  }
} 

// CONSOLE OUTPUT
leads foo controller connected
table filter controller connected
false

@fatk
Copy link

fatk commented May 12, 2023

The issue is with the documentation being unclear about namespaced controllers. See #669 for details.

@adiakritos, you should change the outlet name to the controller's namespaced name:

static outlets = [ 'leads--foo' ]

This part: console.log(this.hasLeadsFooOutlet); should work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants