Page 1 of 1

rule jqvorvRequired with Placeholder<>''

PostPosted: 22 May 2017 13:34
by yocko
Probably simple questions:

#1
Rule jqvorvRequired works only if property Placeholder is empty. How can I assign a required rule if I have:

PlaceHolder := '-- please select --'


#2
I though I can check which items is selected with SelectedIndex. But it doesn't work for me :( See video:Image

I am using this code:
Code: Select all
procedure TKreirajRacunFrame.IWCGJQButton1JQButtonOptionsClick(Sender: TObject; AParams: TStringList);
begin
  WebApplication.ShowMessage('SelectedIndex is '+DropDownDRZAVE.SelectedIndex.ToString);
end;


My settings for DropDown:

DataLink.DataSource := IWUserSession.dsStranke; //datasource for table Customers
DataLink.FieldName := 'Drzava'; //field from table Customers
DataLink.ListDataSource := IWUserSession.dsDrzave; //--> datasource for table Countries
DataLink.ListFetchCount := 120;
DataLink.ListFieldNames := Ime_drzave; //field from table Countries
DataLink.ListLookupResultFieldName := Ime_drzave; //field from table Countries
DataLink.ListSelectFieldName := Ime_drzave; //field from table Countries

Thanks.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 23 May 2017 11:12
by Alexander Bulei
Hi yocko,

#1
Rule jqvorvRequired works only if property Placeholder is empty. How can I assign a required rule if I have:

PlaceHolder := '-- please select --'


Fixed/Change in next beta build.
Thanks.

#2
I though I can check which items is selected with SelectedIndex. But it doesn't work for me :( See video:


When you have ListDataSource assigned, the SelectedIndex will return -1...Use the IWCGJQDropDown.Val, it will return the value of defined field in DataLink.

Best Regards.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 26 May 2017 12:22
by yocko
When you have ListDataSource assigned, the SelectedIndex will return -1...Use the IWCGJQDropDown.Val, it will return the value of defined field in DataLink.


Is it possible to preselect a value in DropDown (populated via DataLink.ListDataSource table Countries)? I want to preselect country when frame shows up (I am calling my procedure Init after frame is created to refresh controls on frame).

I tried with
Code: Select all
procedure TMyFrame.Init;
begin
  DropDownCountries.Val := 'Portugal';

  Region1.AjaxReRender;
end;


Thanks for help.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 30 May 2017 09:44
by Alexander Bulei
Hi yocko,

You need set the Val property as your defined key field (ListSelectFieldName)...I don't think, you have 'Portugal' string as key/id for record.
After you setting the correct value for Val property, the component will lookup in data set, and return ListLookupResultFieldName(field) value:

Code: Select all
ListDataSet.Lookup(ListSelectFieldName,v,ListLookupResultFieldName)


Best Regards.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 06 Jun 2017 11:38
by yocko
Alexander Bulei wrote:Hi yocko,

You need set the Val property as your defined key field (ListSelectFieldName)...I don't think, you have 'Portugal' string as key/id for record.
After you setting the correct value for Val property, the component will lookup in data set, and return ListLookupResultFieldName(field) value:

Code: Select all
ListDataSet.Lookup(ListSelectFieldName,v,ListLookupResultFieldName)


Best Regards.


I still have problems with preselected value.

I have DB Table Countries with two fields: Country_ID (autoinc) and CountryName (string). Each field has its own index.

My settings are:
Code: Select all
Datalink.ListDatasource            := dsCountries (for table Countries)
Datalink.ListSelectFieldName       := 'CountryName';
Datalink.ListLookupResultFieldName := 'CountryName';


I did like
Code: Select all
DropDownCountries.Val:='Portugal';


When I assign a value I want preselected ('Portugal'), DropDown will search for this value in ListSelectFieldName (in my case 'CountryName') and will return ListLookupResultFieldName (in my case 'CountryName'), so it should find 'Portugal' as this value exists in that field.

'Portugal' is selected in DropDown, but when I later control user's input like:
Code: Select all
if Trim(DropDownCountries.Val)='' then
    begin
      WebApplication.ShowMessage('Please select country...');
      DropDownCountries.SetFocus;
      Exit;
    end;


DropDownCountries.Val is empty, although I see value 'Portugal' selected. :o
Image

Please advice. Thanks.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 07 Jun 2017 10:04
by Alexander Bulei
Hi yocko,

Please send us the simple testcase project. TIA

Best Regards.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 07 Jun 2017 19:43
by yocko
Alexander Bulei wrote:Hi yocko,

Please send us the simple testcase project. TIA


I am populating DropDown from a DBISAM Table. I suppose you don't have Dbisam there...

All non DB related code is already posted. After I create a frame I assing value to DropDownCountries.val property. That value (for example country name 'Portugal' is visible as preselected in DropDownCountries when frame gets visible. So far everything is OK. Preselecting some value is working. Then I click on button (see video in my previous post) to display DropDownCountries val value with WebApplication.ShowMessage and it returns '' :o

So:
- populating DropDown from DB table is working OK
- preselecting some value in frame create with assigning value to DropDown's val property is working OK and preselected value is visible in DropDown when frame gets visible. But after this preselection process DropDown's property val is empty!!! :(

My question: are you clearing val property after lookup in DropDown is executed?
Code: Select all
ListDataSet.Lookup(ListSelectFieldName,v,ListLookupResultFieldName)


Otherwise it can't be '' (empty string) if I assigned value 'Portugal' to it when frame was created, and first thing I do when I come to frame is clicking on button to execute:
Code: Select all
WebApplication.ShowMessage('val is: '+DropDownCountries.val)...

So where is value from DropDownCoutries.val property cleared to empty string? Somewhere in between event frame create (where val:='Portugal'), to event frame is visible (where I click on button to test val value and it is already an empty string). One process in between these two events is for sure DropDown's lookup execution, so there something must be wrong... After lookup is finished and some value is preselected ('Portugal' is visible), val poperty should also have value 'Portugal' and not empty string ''...

Regards

P.S:
Additional test from today:

if I have this in on frame create
#1
Code: Select all
DropDownCoutries.val:='Portugal';

val property is empty string when frame gets visible.

#2
if I have this in on frame create
Code: Select all
DropDownCoutries.val:='Portugal';
DropDownCountries.JQDropDownOptions.Open;
DropDownCountries.JQDropDownOptions.Close;

val property is no more empty string when frame gets visible.:)

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 12 Jun 2017 10:03
by Alexander Bulei
Hi yocko,

I've attached the simple demo.

Suggest:
As I said before, it will use the Lookup method in dataset, so I suggest you to check by yourself the code if can find it.

Best Regards.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 12 Jun 2017 23:23
by yocko
Alexander Bulei wrote:Hi yocko,
I've attached the simple demo.


Thanks. It helped. When I copied your DropDown control to my form your control worked and my still didn't (with same settings as yours - I compared them setting by setting). I must had some corruption in my DropDown dfm settings.

DropDown is now working as expected. Case closed!

Thanks again for your help and patience.

Re: rule jqvorvRequired with Placeholder<>''

PostPosted: 13 Jun 2017 12:31
by Alexander Bulei
Hi yocko,

Thanks again for your help and patience.


No problem...we're here to help ;)