StefanoM2 Posted August 27 Share Posted August 27 Hi to all! I'm trying to set a value in a contact form field, but I'm having troubles. In facts, it seems that I can set the value, with this instruction: $('#text-1066fdb2-1602-44d4-9cdb-69681a16189a-field').val("ok").change(); I see the value in the textbox changing, but when I press the button to send the form, the value disappear. It seems that I'm not changing the real field, but a sort of link of it. How can I really set the value of the field? Is it possible? thanks a lot Stefano. Link to comment
paul2009 Posted August 27 Share Posted August 27 40 minutes ago, StefanoM2 said: I'm trying to set a value in a contact form field, but I'm having troubles. It seems that I'm not changing the real field, but a sort of link of it. Form Blocks are now built using React. In React, for every DOM object, there is a corresponding virtual DOM object so, as you mentioned, changing the DOM won't change the form itself. To do this, you'll need to tell React that there's been a change. See earlier threads for more background. Did this help? Please give feedback by clicking an icon below ⬇️ About: SQSP User for 17 yrs. Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF Digital, building Squarespace Extensions to supercharge your commerce website. Content: Links in my posts may refer to SF Digital products or may be affiliate links. If my advice helped, you can thank me by clicking one of the feedback emojis below. I love coffee too. Link to comment
StefanoM2 Posted August 28 Author Share Posted August 28 Thank you for your prompt reply ... I tried the code, everything seems correct, via "console.log" I see correct values, the field doesn't change until a "human" enter value manually in the field. I think I understood the example of codepen: https://codepen.io/anulesh91/pen/XGwZoR and it works, but in squarespace form it doesn't. Any ideas? At least, what I'm trying to do is simply trap 2 additional controls in a form, for example: range of dates, range of hours. I'm not able to "prevent" the form submission in any way (button is not "prevantable"), so I was trying to have a hidden field mandatory, to fill with a value only when my custom controls are ok. That's quite simple, but squarespace doesn't permit me to customify almost nothing 😞 If you have any ideas and / or advices i would appreciate very much. thanks Stefano. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment