Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
gy4443
chemotion_eln_server
Commits
e6fc9d5a
Commit
e6fc9d5a
authored
Aug 20, 2015
by
Marco Sehrer
Browse files
Fix amount value input not updated when unit callback updated value
parent
6128d0c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/assets/javascripts/components/NumeralInput.js
View file @
e6fc9d5a
...
...
@@ -12,6 +12,13 @@ export default class NumeralInput extends Component {
};
}
componentWillReceiveProps
(
nextProps
)
{
let
{
value
}
=
nextProps
;
this
.
setState
({
numeralValue
:
this
.
_convertValueToNumeralValue
(
value
)
});
}
_convertValueToNumeralValue
(
value
)
{
let
{
numeralFormat
}
=
this
.
props
;
return
Numeral
(
value
).
format
(
numeralFormat
);
...
...
app/assets/javascripts/components/SampleDetails.js
View file @
e6fc9d5a
...
...
@@ -84,32 +84,31 @@ export default class SampleDetails extends React.Component {
});
}
render
()
{
let
ajaxCall
=
(
unit
,
nextUnit
,
value
)
=>
{
console
.
log
(
"
ajax call with unit:
"
+
unit
+
"
nextUnit:
"
+
nextUnit
+
"
and value:
"
+
value
);
let
convertedValue
=
value
;
if
(
unit
&&
nextUnit
&&
unit
!=
nextUnit
)
{
switch
(
unit
)
{
case
'
g
'
:
if
(
nextUnit
==
'
mol
'
)
{
convertedValue
=
value
*
2
;
}
break
;
case
'
mol
'
:
if
(
nextUnit
==
'
g
'
)
{
convertedValue
=
value
/
2
;
}
break
;
}
handleUnitChanged
(
unit
,
nextUnit
,
value
)
{
console
.
log
(
"
ajax call with unit:
"
+
unit
+
"
nextUnit:
"
+
nextUnit
+
"
and value:
"
+
value
);
let
convertedValue
=
value
;
if
(
unit
&&
nextUnit
&&
unit
!=
nextUnit
)
{
switch
(
unit
)
{
case
'
g
'
:
if
(
nextUnit
==
'
mol
'
)
{
convertedValue
=
value
*
2
;
}
break
;
case
'
mol
'
:
if
(
nextUnit
==
'
g
'
)
{
convertedValue
=
value
/
2
;
}
break
;
}
console
.
log
(
"
result:
"
+
convertedValue
);
return
convertedValue
;
};
}
console
.
log
(
"
result:
"
+
convertedValue
);
return
convertedValue
;
}
render
()
{
let
sample
=
this
.
state
.
sample
||
{}
let
sampleAmount
=
sample
.
amount_value
&&
sample
.
amount_unit
?
`(
${
sample
.
amount_value
}
${
sample
.
amount_unit
}
)`
:
''
;
let
svgPath
=
sample
.
molecule_svg
?
`/assets/
${
sample
.
molecule_svg
}
`
:
''
;
return
(
<
div
>
<
Panel
header
=
"
Sample Details
"
bsStyle
=
'
primary
'
>
...
...
@@ -138,7 +137,7 @@ export default class SampleDetails extends React.Component {
label
=
"
Amount
"
units
=
{[
'
g
'
,
'
ml
'
,
'
mol
'
]}
numeralFormat
=
'
0,0.00
'
convertValueFromUnitToNextUnit
=
{(
unit
,
nextUnit
,
value
)
=>
ajaxCall
(
unit
,
nextUnit
,
value
)}
convertValueFromUnitToNextUnit
=
{(
unit
,
nextUnit
,
value
)
=>
this
.
handleUnitChanged
(
unit
,
nextUnit
,
value
)}
onChange
=
{(
amount
)
=>
this
.
handleAmountChanged
(
amount
)}
/
>
<
Input
type
=
"
textarea
"
label
=
"
Description
"
ref
=
"
descriptionInput
"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment