Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » how to make an editfield accept only number or date? have any examples in the documentation?
how to make an editfield accept only number or date? have any examples in the documentation? [message #54982] Sat, 03 October 2020 17:56 Go to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

following the example in the AddressBook
imagining that the surname field would only accept numeric or date input.
I tried to understand the SetFilter but I couldn't get success.
is there something simpler that you can understand how to do?

Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #54983 is a reply to message #54982] Sat, 03 October 2020 19:06 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
ops...only number i got it:



modify.surname.SetFilter(OnlyN);

where

int OnlyN(int x){

if((x>=48) && (x<=57)){
return x;
}else{
return false;
}
}


as a date there would have to be a different type of filter to check the position of the number and the characters "/" or "-" delimiting the date.

How do I do that?
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #54988 is a reply to message #54983] Sun, 04 October 2020 03:03 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

in search of understanding how to create a routine that detects data entry of the data type, (to enable validation or even to build formatting)I saw that they use the SetConvert feature. To try to understand how the logic of
use the reference:

Convert :: Convert () {}
Convert :: ~ Convert () {}

What is Convert? a structure? class? something equivalent?
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #54989 is a reply to message #54988] Sun, 04 October 2020 03:10 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
sorry I found it: is class in Convert.h



Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #54996 is a reply to message #54989] Sun, 04 October 2020 09:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You are on the right path!

Mirek
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55004 is a reply to message #54996] Sun, 04 October 2020 17:01 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

see:
... fld.SetConvert(DateIntConvert());
...struct DateIntConvertCls : Convert {
virtual Value Format(const Value& q) const;
virtual Value Scan(const Value& text) const;
virtual int Filter(int chr) const;
};
...Convert& DateIntConvert() {return Single<DateIntConvertCls>(); }
.....

Value DateIntConvertCls::Format(const Value& q) const
{
Date d = Date(1970, 1, 1) + q;
LOG("in format" << "=" << d);
return IsNull(q) ? String() : ::Format(Date(1970, 1, 1) + (int)q);
}

if i want show in "LOG" convert d to a string within

... String s = Format(d); //(*)
... LOG("in format" << "=" << s );

an exception occurs and the test application aborts silently.
If Format (*) returns a String, what would be the problem / inspection?

Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55016 is a reply to message #55004] Mon, 05 October 2020 04:51 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

another related issue:

the editfield fld1 with "SetConvert" fld1.SetConvert(DateIntConvert())

is not receiving data according to the test code below:

void pkTestando:: onClick()
{
Date d = Date ( 2020, 1, 1 );
try
{
Value s = Format ( d );
LOG ( "data " << s );
fld1.SetData ( d );
}
catch ( ValueTypeError )
{
LOG ( "Failed Value conversion" );
}
}

but if he decides to remove condition "SetConvert" the field receives content normally.

What happens ?? or in the condition using "SetCovert" how do I have to write the code?

Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55020 is a reply to message #55016] Mon, 05 October 2020 14:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am not sure: Are you doint this as experimenting / learning example, or you are just not aware about EditDate / EditInt yet?

In any case, look at EditInt code, it is just trivial extenstion of EditField and will explain you about everything about this topic...

Mirek
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55021 is a reply to message #55020] Mon, 05 October 2020 14:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ah, third alternative: Maybe you want single field that contains either Date or int based only on what user entered?

Mirek
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55022 is a reply to message #55021] Mon, 05 October 2020 15:15 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
(I didn't bother to change the name in the functions / classes of the whole prefix "int" but in reality I'm using it for "date")

see, these codes were made based on existing examples.
In the first case, curiously, a format function (inside another "format"
function of the inherited class) generates an exception (and should not).
In this situation, the content is "input date by the user", and the
setconvert was used as a filter so that in customizations,
it could evaluate the date entered. (is there a recursion occurring here ???)

Now in the second case it does not involve input by user, but it is the
same field where simply the same EditField (which uses setconvert)
cannot receive any date "with code". If you remove / disassociate the
setconvert from this editField, it will normally receive the date.

There are 2 problems! (see attached file / very simple example, with 1 field and 1 button/in the initial load of the program, the date is set to "dmy")
)
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55029 is a reply to message #55022] Mon, 05 October 2020 17:43 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Well, I understood question # 2 only (you can disregard it). I was considering that the internal routines would do the conversion. But not. So I understand that when using a field and if associated with SetConvert in the numerical case, when shooting a value for this field in code, I will have to add a corresponding number between the difference of the desired date and the first of January 1970.

Question 1 remains and I believe that only you can clarify the reason for the Format function within another Format of the custom class, it generates an exception. Since the objective in this situation would be the instant that the value resulting from the SetConvert Format was automatically generated, internally the user could evaluate a String of the resulting date.

another problem that i see is that your example "SQLApp in Assembly examples", should not accept typing characters immediately after a valid date (i.e. 01/01/2020abcdef ...)
fld borrowed!

In the code I attached in the previous post i put in filter this content:

if (chr> 57)
{
return false;
}
and in layout MaxChar = 10
Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55037 is a reply to message #55029] Tue, 06 October 2020 00:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You have got it almost right! Great achievement for the first try.

I have fixed some small issues to make it work...

Mirek

[Updated on: Tue, 06 October 2020 09:23]

Report message to a moderator

icon14.gif  Re: how to make an editfield accept only number or date? have any examples in the documentation? [message #55038 is a reply to message #55037] Tue, 06 October 2020 01:54 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 202
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
you are fine with life! this is very good!
little by little I gain understanding.
thank you very much!
Previous Topic: sqlarray and sqlite
Next Topic: How to load your GridCtrl in background thread
Goto Forum:
  


Current Time: Fri Mar 29 07:05:24 CET 2024

Total time taken to generate the page: 0.02258 seconds