Modify the input field in the datepicker to resemble a button

How can I transform an input field into a button that looks like this rather than this ? The simple switch of tag names doesn't seem to work. Any suggestions on how to achieve this?

class MyComponent extends React.Component {
  componentDidMount(){
    this.initDatepicker();
  }
  
  initDatepicker(){
    $(this.refs.datepicker).datepicker();
  }
  
  render(){
    return (
      <div>
        <h3>Choose date!</h3>
        <input type='text'  ref='datepicker' />
      </div>    
    )
  }
}

ReactDOM.render(
  <MyComponent />,
  document.getElementById('app')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/air-datepicker/2.2.3/js/datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/air-datepicker/2.2.3/css/datepicker.min.css" rel="stylesheet"/>

<div id="app"></div>

Answer №1

Transform the appearance of an input to resemble a button:

Example::http://jsfiddle.net/GCu2D/1996/

Styling in CSS:

.input {
  background: #216BA5;
  border: 1px solid #216BA5;
  cursor: pointer;
  color: #FFF;
  padding: 5px 10px;
  border-radius: 4px;
  text-align: center

}

HTML Markup

  <input readonly type="text" class="input" value="2017-07-1" />

The readonly attribute is necessary to make the input clickable but not editable.

If you modify type="text" to type="button", then:

<input type="button" class="input" value="2017-07-1" />

readonly will no longer be needed.

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

Create an interface that inherits from another in MUI

My custom interface for designing themes includes various properties such as colors, border radius, navbar settings, and typography styles. interface ThemeBase { colors: { [key: string]: Color; }; borderRadius: { base: string; mobile: st ...

Allowing web applications to access geolocation permissions through Telegram bots

After developing a Telegram web app bot using React, I incorporated a feature that asks the user for permission to access their current geolocation. However, if the user decides to block this permission, the bot is unable to detect their location. My main ...

Securing Codeigniter against CSRF attacks with AJAX integration

Seeking assistance to troubleshoot a problem with AJAX call in Codeigniter while having CSRF protection enabled. Typically, the system functions smoothly with AJAX/jQuery calls and CSRF protection. However, I am currently facing difficulties with the code ...

An error is thrown when trying to use an imported function from Next.js in the getServerSideProps function, resulting in a 'Reference

In my project, I am utilizing Firebase for authentication. Once the user successfully authenticates, I store their id token in cookies. This allows me to validate the token server-side for Server-Side Rendering (SSR) whenever any request is made to a page ...

Utilize linear gradient effect in editing images and then convert them to base64 format using React

I have been working with the "canvas" library to edit an image via URL using linear-gradient, employing various methods. However, I am facing challenges in achieving the desired results so far. The methods I tried using canvas do not seem to work seamless ...

When a mobile device is rotated, the screen on a jQuery application will automatically shrink

Having trouble with JQM and device rotation on iOS devices. The screen doesn't resize properly when rotated. I have this line in the header to handle display size: <meta name="viewport" content="height=device-height,width=device-width,initial-scal ...

Tips for transferring JavaScript values to PHP through AjaxWould you like to learn how to

Let's set the scene. I'm currently facing a challenge in passing Javascript values to different PHP functions within my ajax code so that they can be properly displayed on the page. Here is the snippet of my code: $("[data-departmen ...

Bug with the button and text input feature in Firefox

I am facing a strange issue where the button and input have the same CSS (except for the background), but Firefox is displaying them differently. This problem does not occur in IE or Chrome. #searchInput { width: 80%; margin: 0 auto; display: ...

The protection ensured by employing an extensive hash in the query string for the recognition of a changing document

I am currently developing a small web application that creates exercise program printouts. The concept is simple - a user like a personal trainer can craft an exercise regimen and send it to their client via email using a unique link. http://www.myurl ...

Navigate the JSON object at predetermined intervals, such as in the case of movie subtitles

Apologies if the title is not specific enough, open to any suggestions for improvement. Here's my issue: I have a JSON file (presented here as a JavaScript object) that contains subtitles for a movie. My goal is to display the text exactly as it appea ...

Encountering an error of "Object Expected" when trying to implement the

I am trying to set up the suckerfish menu as demonstrated on this instructional website. I keep getting an "object expected" error from the sample JavaScript code: $(document).ready(function () { $("#nav-one li").hover( function () ...

Troubleshooting issue: EJS loop not functioning correctly when handling JSON information

Having an issue with looping in an EJS file. Here's the data I'm working with: { "name": "Marina Silva", "info": [{ "periodBegins": "Sun Apr 14 23:48:36 +0000 2011", "periodFinishes": "Sun Apr 7 23:48:36 +0000 201 ...

Tips for using nested flexbox with images

I am facing a straightforward use case where I have an image and a div containing text. The current setting for the div is flex column. My goal is to change the flex setting to row so that the text and image appear side by side. Despite having the corre ...

Choosing the image that represents your website in Safari web previews

Every time I check iCloud.com on my Safari top sites, the thumbnail is always the same. I'm curious about how I can automate this for my own website. ...

Highlight the menu item when you reach a specific section

I am facing difficulties in creating a scrolling menu that highlights the respective item when a specific section is reached. As a beginner in design, I am struggling to achieve this effect. Any insights or guidance on how to implement this would be grea ...

Tips for updating the color, background, and height of the particle background using react-tsparticles

Is it possible to customize color and background in react-tsparticles? Below is an example of a particle configuration file named particle-config.js const particlesConfig = { background: { color: { value: "#232741", }, posi ...

Navigating using passing data in ReactJs

The following data contains information about people: const people = [ { img: 11, name: "Ahmed", job: "developer", }, { img: 13, name: "Kazim", job: "Engineer", }, ...

Exploring CSS shaders in a browser?

Which browser out there fully supports CSS shaders? ...

Extracting data on an AngularJS platform by using web scraping techniques

I have been working on an AngularJS application that currently retrieves JSON data from an API using http.get, and it's been working really well. Recently, I've been exploring the idea of passing a URL to a static webpage and scraping the result ...

Error: JSX elements that are next to each other must be contained within a parent tag

I am trying to display articles on a page using ReactJS, but I encountered an issue where I need to wrap enclosing tags. It seems like React doesn't accept identical tags next to each other. How can I effectively show tabular data? render() { r ...