Giter VIP home page Giter VIP logo

Comments (4)

MichaelWest22 avatar MichaelWest22 commented on September 17, 2024 1

in your first example it reported that the format you specified was not valid json because you had not used the js: or javascript: prefixes to activate hx-vals javascript evaluate feature.

In the second example the value of this.value evaluated to undefined which will throw this error. When it runs the evaluate it runs the eval in global scope where this = window and window does not have a value. To test how it might work just enter the browser dev tools and go to the console of the running application and anything you type into the console here will also be in that same global window state so you can test what works manually this way. often you write a global function to get the data you want to return and then call that function in your hx-vals.

from htmx.

see7e avatar see7e commented on September 17, 2024

Alse, replacing by hx-vals='js:{question_type: this.value}' raises a different error:

htmx.org@2.0.2:1 Uncaught 
TypeError: Cannot read properties of undefined (reading 'forEach')
    at Ln (htmx.org@2.0.2:1:37346)
    at he (htmx.org@2.0.2:1:41107)
    at htmx.org@2.0.2:1:22304
    at HTMLSelectElement.i (htmx.org@2.0.2:1:21340)
Ln	@	htmx.org@2.0.2:1
he	@	htmx.org@2.0.2:1
(anonymous)	@	htmx.org@2.0.2:1
i	@	htmx.org@2.0.2:1

from htmx.

see7e avatar see7e commented on September 17, 2024

found a solution using name=:

hx-post="{% url 'app:update_question_type' pk=question.pk %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-trigger="change"
name="question_type"

Also, looked up in the code, and saw that the hx-vals element only runs JS if used the js: tag, but is strange the error outputed in the comment above. Would be nice if added to the documentation some examples using POST requests :)

from htmx.

see7e avatar see7e commented on September 17, 2024

in your first example it reported that the format you specified was not valid json because you had not used the js: or javascript: prefixes to activate hx-vals javascript evaluate feature.

In the second example the value of this.value evaluated to undefined which will throw this error. When it runs the evaluate it runs the eval in global scope where this = window and window does not have a value. To test how it might work just enter the browser dev tools and go to the console of the running application and anything you type into the console here will also be in that same global window state so you can test what works manually this way. often you write a global function to get the data you want to return and then call that function in your hx-vals.

Hmmmmm that's very elucidative actually! Thank you!

from htmx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.