Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

javascript - Form onSubmit works in desktop but not on mobile

I've done my due diligence in researching this question and the most relevant post:

My React application will not put or post on submit on mobile phones but will work on desktop devices

Did not have any answers so I am asking pretty much the same question. I have a registration form which works fine on Desktop but will not submit on Mobile. I have added "cursor:pointer" to my CSS file for the custom button component but this has not solved the issue.

<form onSubmit={handleSubmit} autoComplete="off">
    ...
          
   <Button type="submit">Register Your Profile</Button>
</form>

My Custom Button Component:

export default function Button({
  children,
  disabled = false,
  type = 'button',
  onClick,
  isSecondary,
  className
}) {
  return (
    <button
      type={type}
      onClick={onClick}
      disabled={disabled}
      className={`${className} ${isSecondary ? '__rival_button_secondary' : '__rival_button'} `}
    >
      {children}
    </button>
  );
}

Again, the form can be submitted on Desktop just fine but not on mobile. How can we fix this? It appears the Button needs some kind of an onClick event handler but why is this the case for mobile only? The only relevant documentation I could find: https://github.com/facebook/create-react-app/issues/4290 does not address the mobile issue specifically.

I've tried adding onClick, onTouchStart to Button but this does not capture the form submit event. I've also tried adding an 'id' tag to the form but all to no avail.

question from:https://stackoverflow.com/questions/65850624/form-onsubmit-works-in-desktop-but-not-on-mobile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...