Unable to trigger ActionFunction with Remix and MUI slider

I am trying to implement a MUI slider in order to update a database by using Remix ActionFunction.

The issue I am facing is that when the MUI slider is moved, it reloads the default function instead of calling the ActionFunction. How can I make it trigger the action?

This is how the route appears:

export default function AdminOrganizationSettingsGeneral(setOrgTeam: any) {
  const actionData = useActionData<typeof action>();

  const setChanges = async (event: Event, value: number) => {
    console.log("submitting!");
    return submit(event.target.name, value);
  };   

  return (
    <PaperCustom sx={{ width: "100%" }}>
      {teams.map((val, index) => (
        <Grid container sx={{ padding: "1rem" }}>
          <Grid item md={2} xs={3}>
            <Typography>{val.status}</Typography>
          </Grid>
          <Grid item md={3} xs={6}>
            <Typography>{val.name}</Typography>
          </Grid>
          <Grid item md={3} xs={3}>
            <Typography>Team: {val.members}</Typography>
          </Grid>{" "}
          <Grid item md={4} xs={12}>
            <DiscreteSlider
              setChanges={setChanges}
              teamValue={val.setup ? val.setup : 10}
              name={val._id}
            />
          </Grid>
        </Grid>
      ))}
    </PaperCustom>
  );
}

This is the DiscreteSlider component:

export default function DiscreteSlider(props: any) {
  const submit = useSubmit();

  return (
    <Form
      method="post"
      onChange={(event) => {
        submit(event.currentTarget);
      }}
    >
      <Box sx={{ width: "100%" }}>
        <Slider
          type="submit"
          aria-label="Temperature"
          defaultValue={props.teamValue}
          step={10}
          min={10}
          max={30}
          marks={marks}
          onChange={(event: Event, value: number) => {
            submit(event, value);
          }}
          {...props}
        />
      </Box>
    </Form>
  );
}

Whenever I modify the slider, it causes the AdminOrganizationSettingsGeneral function to reload, thereby updating the DOM. However, it fails to trigger the ActionFunction as intended... (see below)

ActionFunction

export const action: ActionFunction = async (args: ActionArgs) => {
  const { request, context, params } = args;
  const { orgId = "", teamId = "" } = params;
  const form = await request.formData();

  console.log("This is not happening...");
};

Answer №1

Make sure to include method: post when using the submit function. By default, the submit method is set to get. Keep in mind that you are invoking the submit function from the useSubmit hook, not the form submit itself.

onChange={(event: Event, value: number) => {
  submit({ temperature: value }, { method: 'post' });
}}

Then, in your action, you can retrieve the form data like this:

const formData = await request.formData()
const temperature = Number(formData.get('temperature'))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to call a script function in PHP and expecting a return value, an error was encountered: "Uncaught SyntaxError

My functions are working fine: <script> function createCookie(name,value,sec) { if (sec) { console.log('createCookie: '+name+', '+value+', '+sec); var date = new Date(); date.setTime(date.getTime()+(sec*1000 ...

Create copies of a single array containing objects in various new arrays

I need to create duplicates of an array of objects multiple times, as I require each one for different uses. if(!this.tempLookups){ for (let count = 0; count < this.dates.length; count++) { this.tempLookups[count] = this.lookups[key]; } ...

Changing the color of a Highcharts series bar according to its value

Playing around with Highcharts in this plunker has led me to wonder if it's possible to dynamically set the color of a bar based on its value. In my current setup, I have 5 bars that change values between 0 and 100 at intervals. I'd like the colo ...

Error message displayed for invalid date format in Material UI (dateTime picker) after form submission

I recently integrated the Material Ui DateTime picker into my form. However, upon submitting the form, I encountered the following error: Invalid Date Format Image In my React app, I am utilizing JSON Server to store data. Displayed below is the outpu ...

Tips for ensuring jwt token is not lost when refreshing a page in an angularjs app

My project involves authorizing users using jwt tokens, but I am facing an issue where the token is lost upon page refresh and subsequent requests to the server do not include the token. The setup includes storing the token in local storage and utilizing ...

Utilize Autocomplete component from Material UI to sift through distinct option values

Looking to implement unique options in the dropdown menu of an Autocomplete component from Material UI based on a specific property within a list of objects. The current issue is that duplicate values are appearing in the dropdown, like ['Color1&apos ...

A guide on how to effectively simulate a commonJS module that has been imported in

How can I successfully mock a commonJS style module in Jest that I am importing for an external connection? The module is called 'ganblib.js' and it's causing some trouble when trying to mock it with Jest. Any advice or suggestions would be ...

A status code of 200 indicates a successful login, which then leads to a 401 status code upon making a

Just recently, I successfully deployed a rails backend and a vue frontend to Heroku. Everything was working fine until today when I encountered a problem while trying to log in to the web app. Immediately after logging in, I started receiving 401 responses ...

Ensure each list item is directly aligned when swiping on a mobile device

Looking to make a simple horizontal list swipeable on mobile devices with tabs that snap from tab to tab, activating the content for the active tab immediately. The desired effect is to swipe directly from one tab to the next without having to click separ ...

Best practices for sending an object from client to server using Node.js

What is the best way to transfer a large object from client side to my node.js server? The object is currently stored in a variable within my script tags. ...

Identify input elements that specifically contain an onclick event

Several of the input elements on my page have a function called setSomeFunction() that either shows or hides certain divs when clicked. I know I can locate all the input elements using document.getElementsByTagName("input") and store them in an array. How ...

What could be causing the delay in Express when transitioning between console logs while using AngularJS $http.get?

By utilizing Express, Node, and Angular, I incorporated an HTML button on my website that triggers a get request to Express. This request then executes a function that logs a predefined message to the console. Initially, when I click the button for the fir ...

What is the best way to incorporate a JavaScript function into an Angular 2 template?

I need a slider for my project and I am using AdminLTE <input type="text" value="" class="slider form-control" data-slider-min="-200" data-slider-max="200" data-slider-step="5" data-slider-orientation="horizontal" data-slider-sele ...

What is the best way to organize divs in a grid layout that adapts to different screen sizes, similar to the style

Is there a way to align multiple elements of varying heights against the top of a container, similar to what is seen on Wolfram's homepage? I noticed that they used a lot of JavaScript and absolute positioning in their code, but I'm wondering if ...

Tips on enhancing an array by separating values with vertical bars instead of commas

I am trying to store checked values in an array and separate them with vertical bars instead of commas. Is there a way to achieve this using the jQuery map .get() function? Any suggestions or links you can provide would be greatly appreciated. Thank you in ...

Is it possible for me to retrieve/load a <datalist> element from a different file?

I'm in the process of developing a Google Chrome extension that essentially consists of a dropdown menu and an input box with datalists. The user can change their selection in the dropdown menu, which will then switch the datalist being used by the in ...

Tapping on an HTML element that is populated from PHP using jQuery AJAX may fail to function

I am facing an issue with a page where clicking a button should display a table with an "id" attribute that is loaded through jQuery AJAX with PHP. Strangely, the click event on table cells is not working in my JavaScript. Can someone please take a look at ...

Troubleshooting overload errors within ReactJS: tips and tricks

import React from 'react' import { Link } from 'react-scroll' import "./Protocol.css" import { ANALYTICS, TRADE, USERS, TRADERS, VOTES, ZEROES } from "../../Constants" const Protocol = () => { return ( ...

Troubleshooting Problems with POST Requests in ExpressJS

Currently, I am working on developing a feature in NodeJS that allows users to upload files. However, I am encountering difficulties while attempting to make a simple POST request. In my index.ejs file, I have written code that generates a form and initia ...

JWPlayer encounters an issue: "undefined" function is not defined

Can anyone lend a hand with this issue I'm facing? I'm attempting to upload a video using jwplayer but encountering errors. Here is the snippet of code I'm utilizing: <script type="text/javascript"> jwplayer("leg ...