Questions tagged [form-with]

37 questions
8
votes
1 answer

Rails 7: local (non-XHR) request with a form_with form

In Rails 7 a form generated with form_with tag sends remote request by default (turbo.js handles form submit event instead, whatever). Previously one would pass remote: false or local: true parameters to form helper, to get just a regular HTML form…
installero
  • 9,096
  • 3
  • 39
  • 43
3
votes
1 answer

Rails form_with hidden_field value encrypted for new object

I have a simple form for creating a new model. The model has an attribute panel that is set in the Controller. I think it should not matter, but panel is an enum. def new @order = Order.new(panel: params[:panel]) end In the view I create the…
MeXx
  • 3,357
  • 24
  • 39
2
votes
0 answers

Rails add style to field :required

I would like to style the small dialog box that appears when I add a :required => true on my form. Is it something that can be done? I can't find anything when inspecting the dom, it's like this small dialog doesn't even exist and can't be selected.
hbrouc
  • 21
  • 3
2
votes
2 answers

Errors not displaying when rendering edit in Rails 7

My app is running Rails Rails 7.0.2.3 In my update controller action I have the line: return render(:edit) unless @user_form.save This renders the edit view on error .... but errors are not displayed. In my edit view I am defining the form…
ReggieB
  • 8,100
  • 3
  • 38
  • 46
2
votes
2 answers

Change 'Please match the format requested.' to something else?

Is there an easy way to customise the message that appears when the pattern: "([A-Za-z0-9\-\_]+)" argument is not satisfied and this message appears: e.g. <%= f.text_field :username, pattern: "([A-Za-z0-9\-\_]+)" %>
stevec
  • 41,291
  • 27
  • 223
  • 311
2
votes
2 answers

How to add a hidden field to form_with?

I am attempting to add a hidden field to a form_with. Here are 3 attempts (and results / error messages) First attempt From: https://guides.rubyonrails.org/form_helpers.html <%= hidden_field_tag(:parent_id, "5") %> So I try: <%= form_with(model:…
stevec
  • 41,291
  • 27
  • 223
  • 311
1
vote
1 answer

Rails 7: Forms having two buttons (One for GET request and One for POST request)

I am working on Ruby on Rails application and have designed a form. I have two buttons in the form. Generate Plot button which initiates a GET request Save button which initiates a POST request. The GET request is working alright and I am able to…
1
vote
2 answers

How do I connect a general search form (form_with helper) to a specific route and pass the input to the params hash?

I'm having trouble connecting a form_with helper to a specific action. I want to search through my posts and so have created a search action in the posts_controller. The logic is working (tested by typing in the request in the url manually) but I…
1
vote
1 answer

Rails form_with select selected option

I have a form without a model backing it built using form_with in Rails 6: <%= f.text_field :one %> <%= f.select :two, [['Option 1',1],['Option 2',2]] %> <%= f.submit 'Submit' %> The only documentation I can find to set which of the select…
RedBassett
  • 3,469
  • 3
  • 32
  • 56
1
vote
1 answer

How to change the message when a form input doesn't match the pattern parameter?

A pattern argument can be provided to a form field as described here Example (regex from here) <%= f.text_field :username, pattern: "([A-Za-z0-9\-\_]+)" %> When the regex is not adhered to, a message is displayed. E.g.: How can that message be…
stevec
  • 41,291
  • 27
  • 223
  • 311
1
vote
1 answer

Custom route param and form_with not using the param

I'm trying to allocate an address a custom id so it's not easy to guess the record (for people who want to add and change other people's addresses). For some reason, whilst I can create a record with the correct path being created, the edit path…
Darren
  • 1,682
  • 1
  • 15
  • 33
1
vote
1 answer

Can't make Stimulus JS data-action in collection_select Rails 6

I'm new to Stimulus JS. I'm a little stuck trying to make a simple event fire using collection_select in a form (created with rails g scaffold). Here's my dropdown-controller.js (stimulus) file: import { Controller } from "stimulus" export default…
1
vote
2 answers

Ruby on rails, can't update database via web interface

I'm programming a Book library system with a SQL Lite database in the background. Via the console I can add and update books without a problem. And I have already made a view where I can add new books and it works great. But now I'm trying to make a…
aa.hari.csbe
  • 90
  • 1
  • 8
1
vote
1 answer

How to use Rails 5.2 form_with to trigger a specific action?

My application needs to duplicate a Skill (from skills index) as many times the user needs it in his cart. So I decided to trigger the add-to-cart method of the skills_controller when the related form, including the number of duplicates and the…
user1185081
  • 1,898
  • 2
  • 21
  • 46
1
vote
1 answer

Nested routes - rails 5.2.4 - Undefined local variable or method

To register addresses for clients in my application I am using nested routes, however when clicking on the link to register a new address or to edit an existing address the system presents the error: undefined local variable or method `address' for…
1
2 3