如何限制用户在 NumberEditBox 中输入的数字为 7 位?ECN = 0,
Text Box( "System ECN:" ),
S1 = Number Edit Box(ECN, <<SET property=""></SET>
The user shouldn't be able to enter more than 7 digits. For example: 1234567... the user shouldn't be able to enter 8.
How did achieve this?
Any help is appreciated.
<LINGO-LABS id="lingo-labs-750800" slang="en-US" mode="CREATE"><LINGO-LABEL>数据探索与可视化</LINGO-LABEL><LINGO-LABEL>视窗</LINGO-LABEL></LINGO-LABS>回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?嗨@PunitPanjwani
这是脚本索引中 set numberchanged() 和 get numberchanged() 示例的修改版本。我认为这已经非常接近您的目标了:
Names Default To Here( 1 );
New Window( "Example",
numBox = Number Edit Box(
.,
10,
<< set number changed(
Function( { thisBox, value }, /* put my value into my sibling's display */
if( length( char( value ) ) > 7,
// > 7 digits
thisBox << set( . );
( thisBox << sib ) << settext( "Too many digits" ),
// <= 7 digits
( thisBox << sib ) << settext( char( value ) )
)
)
)
),
Text Box( "" )/* here's the sibling box, waiting to show a message */
);
numBox << get number changed()
回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?您在哪里找到此消息:
<< Set Max Length(7) // Limit the number of digits to 7
我没有在数字编辑框的协议中看到它。
回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?谢谢马克!
我修改了代码如下,但仍然没有成功。你认为这在 JMP 软件中很重要吗?
Names Default to Here( 1 );
last = eon = 0;
New Window( "Only Seven",
Outline Box( "Enter EON",
Line Up Box( N Col( 2 ),
Text Box( "System EON:" ),
neb = Number Edit Box( eon,
<< Set Integer Only( 1 ),
<< Set Minimum( 0 ),
<< Set Tip( "Enter an integer number with no more than 7 digits")
<< Set Number Changed(
Function( { self, number },
If( Length( Char( number ) ) > 7,
self << Set( last ),
last = number
);
);
),
<< Set Max Length(7) // Limit the number of digits to 7
)
)
)
)回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?你可以朝这个方向开始。
Names Default to Here( 1 );
last = eon = 0;
New Window( "Only Seven",
Outline Box( "Enter EON",
Line Up Box( N Col( 2 ),
Text Box( "System EON:" ),
neb = Number Edit Box( eon,
<< Set Integer Only( 1 ),
<< Set Minimum( 0 ),
<< Set Tip( "Enter an integer number with no more than 7 digits")
<< Set Number Changed(
Function( { self, number },
If( Length( Char( number ) ) > 7,
self << Set( last ),
last = number
);
);
)
)
)
)
)回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?此版本要求用户提交对号码的更改。
Names Default to Here( 1 );
last = eon = 0;
New Window( "Only Seven",
Outline Box( "Enter EON",
Line Up Box( N Col( 2 ),
Text Box( "System EON:" ),
neb = Number Edit Box( eon,
<< Set Integer Only( 1 ),
<< Set Minimum( 0 ),
<< Set Tip( "Enter an integer number with no more than 7 digits"),
<< Set Function( // called when user commits data entry
Function( { self },
new = self << Get;
If( Length( Char( new ) ) > 7,
self << Set( last ),
last = new
);
);
)
)
)
)
);回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?有多种方法可以实现此目的,具体取决于您希望 UI 如何运行:
- 如果用户输入的数字太多,则抛出错误消息
- 如果用户输入的数字过多,则将值设置为允许的最大数字
- 如果用户插入的数字太多,则将值设置为空值(缺失值)
- 如果用户输入的数字过多,则将值设置为最后一个“有效”值
- ...
然后,您必须决定何时更新值:在提交时还是在每次数字改变时?
以下是一些选项,可以根据需要进行组合
查看更多...
Names Default To Here(1);
nw = New Window("Example",
Lineup Box(N Col(2),
Text Box("Set to max value on COMMIT:"),
Number Edit Box(
.
, 10
, << Set Maximum(9999999)
, << Set Exclude Maximum(0)
, << Set Integer Only(1)
),
Text Box("Set to last COMMITTED value on COMMIT:"),
cb = Context Box(
box:last_val = .;
Number Edit Box(
.
, 10
, << Set Function(function({this},
If((this << get) >= 10000000,
this << set(box:last_val)
,
box:last_val = this << get;
)
))
)
),
Text Box("Throw on COMMIT"),
cb = Context Box(
box:last_val = .;
Number Edit Box(
.
, 10
, << Set Function(function({this},
If((this << get) >= 10000000,
this << set(box:last_val);
Throw("No values longer than 7 digits allowed");
,
box:last_val = this << get;
)
))
)
),
Text Box("Set to last changed value on change and break focus:"),
cb = Context Box(
box:last_val = .;
Number Edit Box(
.
, 10
, << Set Number Changed(function({this, val},
If((val) >= 10000000,
this << set(box:last_val);
box:mb << Set Focus(1); // to break focus from number edit box
,
box:last_val = val;
)
))
),
Unlineup Box(box:mb = Mouse Box());
)
)
);
回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?谢谢你,马克!
回复:如何将用户在 NumberEditBox 中输入的数字限制为 7 位?谢谢你,贾莫!