-3
votes

Activez le bouton Aller à la prochaine étape, essayé de configurer l'état et créé une nouvelle méthode OnClick dans le bouton radio

Mise à jour 2: strong>

hi, p>

  • Désolé j'ai oublié de mentionner l'appel de l'API dans ma question précédente li>
  • Je fais un appel API à Regux Way. Li>
  • Donc, dans mon fichier Actions / Index.js, j'appelle mon API dans la méthode Getsports. Li>
  • Mais le problème est quand j'essaie de récupérer les valeurs, je reçois une erreur. Une erreur d'origine croisée a été lancée. Réagir n'a pas accès à l'objet d'erreur réel dans le développement. Voir b.me/react-crossorigin-Error pour plus d'informations. Code> Li>
  • j'ai donc débogué les accessoires dans la classe asyncvalidationform console.log ("asyncvalidationform this.props ------->", cela.props); code> li> li>
  • là je ne vois pas la méthode getsports. li>
  • Pouvez-vous me dire comment récupérer les valeurs afin que je puisse l'affecter à mon étiquette de mon bouton radio. LI> ul>

    https://codesandbox.io/s/yv1zpj874x P>

    actions / index.js strong> p> xxx pré>

    asyncvalidationform.js strong> p> xxx Pré>

    étiquette de bouton radio dans asyncvalidationform.js strong> p> xxx pré>

    • Je suis nouveau à Redux Formulaire. Li>
    • J'essaie d'activer le bouton après que je clique sur le bouton radio. LI>
    • Pour activer le bouton d'aller à l'étape suivante, j'ai essayé de configurer l'état et créé une nouvelle méthode OnClick dans le bouton radio. LI>
    • mais toujours sa lancement d'une erreur, li>
    • Vous ne savez pas comment transmettre les valeurs de bouton radio pour activer le bouton. LI>
    • Pouvez-vous me dire comment le réparer, de sorte que, à l'avenir, je vais le réparer moi-même. Li>
    • Fournir mon sandbox et mon extrait de code pertinent ci-dessous. Li> ul>

      update1: Maintenant, seule cette erreur a été supprimée forte> https://codesandbox.io/s/4JPKK394x7?modulteview=1 P >

      https://codesandbox.io/s/pjj6m1l9pq p>

      asyncvalidationform.js strud> p> xxx pré>

      steppleplate.js strong> p>

      <Button
                variant="contained"
                color="primary"
                onClick={onNext}
                className={classes.button}
              >
                {canGoBack ? "Next" : "go to next step"}
              </Button>
      


6 commentaires

Votre sable de sable devrait être un exemple minimal . Si les extraits ci-dessus sont le code correspondant, il ne devrait pas y avoir presque rien d'autre dans votre bac à sable.


@Ryancogswell hey j'ai enlevé les fichiers inutilisés, pouvez-vous m'aider maintenant


La bac à sable ne me semble pas différente.


Hey j'utilise pas à pas et réduisez la forme afin que ces codes soient là ... Je ne sais pas comment reproduire en supprimant ces codes ... Pouvez-vous me faire savoir


@Ryancogswell j'ai essayé dans ma boite de sable, sa ne fonctionne pas ... Pouvez-vous mettre à jour dans mon bac à sable


@nossr Je pense que la réponse n'est plus verrouillée.


3 Réponses :


0
votes

Ceci est un code simple pour activer un bouton sur le bouton radio click Si vous voulez un plus de descriptif, il vous plaît élaborer votre question

p>

<html>
<script>
function enableButton()
{
	document.getElementById("button").disabled = true;
}
</script>
<input type="radio" name="gender" value="male" onclick="JaaScript:enableButton()"> Male<br>
<button type="button" id="button">Click Me!</button>
</html>


2 commentaires

Hey in asyncvalidationform.js j'ai ajouté le bouton radio Pouvez-vous ajouter des événements clics là-bas .... Pour que cela m'aidera à continuer .... Pouvez-vous mettre à jour dans mon bac à sable directement


J'ai essayé dans mon bac à sable, sa ne fonctionne pas ... Pouvez-vous mettre à jour dans mon bac à sable




1
votes

https://codesandbox.io/s/6zrw7r66rr

J'ai fourré votre codesandbox et éditez 4 fichiers. À peu près sûr, il répond à toutes vos exigences énoncées ci-dessus P>

VerticallineErStepper.js: C'est ici que nous stockons notre nom d'utilisateur Nom d'utilisateur, mot de passe, désactivé (Radiobutton) code> état et HandLechange Code > Méthode pour SetState code>. Ensuite, nous avons transmis l'état à -> step1.js code> -> asyncvalidationform.js code>. P> xxx pré>

in asyncvalidationform.js code>, nous lions Onchange code> pour suivre la valeur et appeler la méthode setState code> et ceci.props.handlechange code> Pour setState code> dans verticallinearsepper.js code> p> xxx pré>

puis, dans steppleplate.js code> Ajouter désactivéNext, checkdisabledNext code> accessoires. CheckDisableDNexgère Code> Pour déterminer si le bouton Suivant aura une vérification conditionnelle ou non. désactivéNexTe code> est la valeur désactivée. p> xxx pré>

ceci est step1.js code>, nous passons ici des accessoires à Steptemplate code> et asyncvalidationform code>: p> xxx pré>

Voici le correctif de la ré-rendu: https://codesandbox.io/s/vqvxj7ky4y Mise à jour verticallineeepper.js code>, alors nous n'avons plus besoin de fichier step1.js, puisque nous écrivons le contenu de STEP1.JS dans ce fichier: P>

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Stepper from "@material-ui/core/Stepper";
import Step from "@material-ui/core/Step";
import StepLabel from "@material-ui/core/StepLabel";
import StepContent from "@material-ui/core/StepContent";
import Button from "@material-ui/core/Button";
import Paper from "@material-ui/core/Paper";
import Typography from "@material-ui/core/Typography";

// import Step1 from "./steps/Step1";
import Step2 from "./steps/Step2";
import Step3 from "./steps/Step3";

import StepTemplate from "./steps/StepTemplate";
import AsyncValidationForm from "./forms/AsyncValidationForm";

const styles = theme => ({
  root: {
    width: "90%"
  },
  button: {
    marginTop: theme.spacing.unit,
    marginRight: theme.spacing.unit
  },
  actionsContainer: {
    marginBottom: theme.spacing.unit * 2
  },
  resetContainer: {
    padding: theme.spacing.unit * 3
  }
});

class VerticalLinearStepper extends React.Component {
  state = {
    activeStep: 0,
    //we set our state in this parent
    disabledNext: true,
    username: "",
    password: ""
  };

  steps = {
    //we pass the content of Step1 here, so we dont have to pass props
    "Select campaign settings": props => (
      <StepTemplate
        text={`
        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.

        For each ad campaign that you create, you can control how much you're
        willing to spend on clicks and conversions, which networks and
        geographical locations you want your ads to show on, and more.
    `}
        //we want to apply checking on Step1.js, so we add checkDisabledNext attribute
        checkDisabledNext={true}
        disabledNext={this.state.disabledNext} //use this class' state
        {...props}
      >
        <form>
          form for the first step here
          <div>test here</div>
          <AsyncValidationForm
            onSubmit={values => {
              console.log(values);
              alert(
                `Values: username: ${values.username} password: ${
                  values.password
                }`
              );
            }}
            //we use this class setstate , no need to pass down props
            handleChangeDisabledNext={this.handleChangeDisabledNext}
            disabledNext={this.state.disabledNext}
            handleChange={this.handleChange}
            username={this.state.username}
            password={this.state.password}
          />
        </form>
      </StepTemplate>
    ),
    "Create an ad group": Step2,
    "Create an ad": Step3
  };

  //setState for disabledNext
  handleChangeDisabledNext = value => {
    this.setState({ disabledNext: value });
  };
  //setState for username, password
  handleChange = (name, value) => {
    this.setState({ [name]: value });
  };

  stepsCount = () => Object.values(this.steps).length;

  canGoBack = () => this.state.activeStep > 0;
  canGoForward = () => this.state.activeStep < this.stepsCount();

  isFinished = () => this.state.activeStep === this.stepsCount();

  handleBack = () => {
    if (this.canGoBack()) {
      this.setState(prevState => ({ activeStep: prevState.activeStep - 1 }));
    }
  };

  handleNext = () => {
    if (this.canGoForward()) {
      this.setState(prevState => ({ activeStep: prevState.activeStep + 1 }));
    }
  };

  handleReset = () => this.setState({ activeStep: 0 });

  render() {
    const { classes } = this.props;
    const { activeStep } = this.state;

    return (
      <div className={classes.root}>
        <Stepper activeStep={activeStep} orientation="vertical">
          {Object.entries(this.steps).map(([label, CustomStep]) => (
            <Step key={label}>
              <StepLabel>{label}</StepLabel>
              <StepContent>
                <CustomStep
                  canGoBack={this.canGoBack()}
                  canGoForward={this.canGoForward()}
                  onBack={this.handleBack}
                  onNext={this.handleNext}
                  classes={classes}
                />
              </StepContent>
            </Step>
          ))}
        </Stepper>

        {this.isFinished() && (
          <Paper square elevation={0} className={classes.resetContainer}>
            <Typography>All steps completed - you&apos;re finished</Typography>
            <Button onClick={this.handleReset} className={classes.button}>
              Reset
            </Button>
          </Paper>
        )}
      </div>
    );
  }
}

VerticalLinearStepper.propTypes = {
  classes: PropTypes.object
};

export default withStyles(styles)(VerticalLinearStepper);


3 commentaires

Les commentaires ne sont pas pour une discussion prolongée; Cette conversation a été Déplacé pour discuter .


@Alvin pour conserver la valeur de la zone de texte votre utilisation Nom d'utilisateur: "", mais comment retenir les valeurs de bouton radio


@nossr n'ajoute plus de commentaires, nous pouvons utiliser le chat