-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added component DateTime field (#56)
* Added component DateTime field * Added correct PR number to changelog
- Loading branch information
Showing
6 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ var | |
/include | ||
/.Python | ||
/lib | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from "react" | ||
|
||
|
||
class DateTime extends React.Component | ||
|
||
###* | ||
* DateTime field for the Listing Table | ||
* | ||
* A datetime field is identified by the column type "datetime" in the listing | ||
* view, e.g. `self.columns = {"Result": {"type": "datetime"}, ... }` | ||
* | ||
### | ||
constructor: (props) -> | ||
super(props) | ||
|
||
# remember the initial value | ||
@state = | ||
value: props.defaultValue | ||
|
||
# bind event handler to the current context | ||
@on_change = @on_change.bind @ | ||
|
||
###* | ||
* componentDidUpdate(prevProps, prevState, snapshot) | ||
* This is invoked immediately after updating occurs. | ||
* This method is not called for the initial render. | ||
### | ||
componentDidUpdate: (prevProps) -> | ||
if @props.defaultValue != prevProps.defaultValue | ||
@setState value: @props.defaultValue | ||
|
||
###* | ||
* Event handler when the value changed of the datetime field | ||
* @param event {object} ReactJS event object | ||
### | ||
on_change: (event) -> | ||
el = event.currentTarget | ||
# Extract the UID attribute | ||
uid = el.getAttribute("uid") | ||
# Extract the column_key attribute | ||
name = el.getAttribute("column_key") or el.name | ||
# Extract the value of the datetime field | ||
value = el.value | ||
|
||
# store the new value | ||
@setState | ||
value: value | ||
|
||
console.debug "DateTime::on_change: value=#{value}" | ||
|
||
# Call the *update* field handler | ||
if @props.update_editable_field | ||
@props.update_editable_field uid, name, value, @props.item | ||
|
||
render: -> | ||
<span className="form-group"> | ||
{@props.before and <span className="before_field" dangerouslySetInnerHTML={{__html: @props.before}}></span>} | ||
<input type="datetime-local" | ||
size={@props.size or 20} | ||
uid={@props.uid} | ||
name={@props.name} | ||
value={@state.value} | ||
column_key={@props.column_key} | ||
title={@props.title} | ||
disabled={@props.disabled} | ||
required={@props.required} | ||
className={@props.className} | ||
placeholder={@props.placeholder} | ||
onChange={@props.onChange or @on_change} | ||
tabIndex={@props.tabIndex} | ||
{...@props.attrs}/> | ||
{@props.after and <span className="after_field" dangerouslySetInnerHTML={{__html: @props.after}}></span>} | ||
</span> | ||
|
||
|
||
export default DateTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters