use fields without a dataprovider attached

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

use fields without a dataprovider attached

Postby IT2Be » Wed Oct 05, 2005 11:47 am

This is COOL, this is GREAT...

Didn't know this could be done but after 5 minutes of brainwashes I came upt with this:

1. add a field to your form and set the dataprovider to none
2. name your field (example = 'fieldname')
3. create a method (example = 'changed_field')
4. add the following code to the method:
Code: Select all
elements.fieldname.selectAll();
application.output(elements.fieldname.getSelectedText());

5. attach the method to the onFocusLost event
6. go to browse mode and test the stuff!

The only thing left is that you add your own datachanged check since this event, like onaction, won't work.

To be honest, I love my own tip :)

Cheers
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby maarten » Wed Oct 05, 2005 12:50 pm

There goes one of our dutch dare devils again.
:twisted:
Works fine in recordview. Not ment for list/table view.

Great tip for using "virtual" columns!

Thanks Marcel.
(also for your contribution to the conference)
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby IT2Be » Wed Oct 05, 2005 1:00 pm

Thanks for the compliments Maarten. I am blushing as we speak and my breath burned all equipment I have (or had) :)

The tip also doesn't work on a password field since a password field doesn't let you select the value...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: use fields without a dataprovider attached

Postby log-out » Wed Dec 28, 2005 5:47 pm

What's the difference between this:
Code: Select all
elements.fieldname.selectAll();
application.output(elements.fieldname.getSelectedText());

And this?
Code: Select all
elements.fieldname.selectAll();
elements.fieldname.getSelectedText();

I don't understand what application.output() does.

Another question: How can I clean up a field without dataprovider? I tried this:
Code: Select all
elements.fieldname.selectAll();
elements.fieldname.replaceSelectedText('');

but I receive a "java.lang.NullPointerException"(?!?) error :cry:
log-out
 
Posts: 180
Joined: Sat Feb 19, 2005 4:20 pm
Location: Spain

Postby maarten » Wed Dec 28, 2005 6:02 pm

application.output();
is for testing purposes only. output is displayed in the output tab(bottom right corner of the editor)


but I receive a "java.lang.NullPointerException"(?!?) error

Make sure that the element in your form actually HAS a name (name property)
otherwise you can't "grab" it using elements.fieldname....
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby log-out » Thu Dec 29, 2005 11:40 am

maarten wrote:Make sure that the element in your form actually HAS a name (name property)
otherwise you can't "grab" it using elements.fieldname....

I find the elements in the elements tree of the form, so the elements have a name.
log-out
 
Posts: 180
Joined: Sat Feb 19, 2005 4:20 pm
Location: Spain

Postby log-out » Thu Dec 29, 2005 12:05 pm

It seems that replaceSelectedText() only works with fields WITH dataprovider attached :(
log-out
 
Posts: 180
Joined: Sat Feb 19, 2005 4:20 pm
Location: Spain

Postby maarten » Thu Dec 29, 2005 12:08 pm

elements.fieldname.selectAll();
elements.fieldname.replaceSelectedText('');


This code should work fine.
Can you give me a sample solution?
I can't give an answer based on given info.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby maarten » Thu Dec 29, 2005 12:15 pm

ah ok.

You can also create a (unstored) calculation with code "return ;"
Attach this calc to your element.

This will also act as a "virtual" column.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby log-out » Thu Dec 29, 2005 12:41 pm

It works, thanks.

But then, if I attach a calculation (e.g., 'fieldname_calc') to a element ('fieldname'), I don't need this:

Code: Select all
elements.fieldname.replaceSelectedText('');

Because I can use this:
Code: Select all
fieldname_calc = '';
log-out
 
Posts: 180
Joined: Sat Feb 19, 2005 4:20 pm
Location: Spain

Postby maarten » Thu Dec 29, 2005 1:18 pm

exactly.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Re: use fields without a dataprovider attached

Postby grahamg » Thu Sep 25, 2008 4:37 pm

Hi all

Found this ancient thread while trying to resolve issue with 'selectAll()'

Trying to grab field name + data pairs on a Form and paste them into a text field for later re-use.

Hard coding the field name works but using a variable crashes out. Am I missing something obvious???

Code: Select all
Function b_GetFields()
{
   var vElemArray = alldataproviders;
   var vField = null;
   var vData = null;
      
   for (var i=0 ; i<vElemArray.length ; i++)
   {
      vField    = vElemArray[i];
      
//***  this does not work - stops debgger at vData line
      elements[vField].selectAll();
      vData      = elements[vField].getSelectedText();

//***  this works as expected
//      elements.company_name.selectAll();
//      vData      = elements.company_name.getSelectedText();

//    .... paste into TextField...
}



Thanks in advance

Servoy 4.0.1

Graham
Graham Greensall
Worxinfo Ltd
www.worxinfo.com
grahamg
 
Posts: 752
Joined: Fri Oct 03, 2003 3:15 pm
Location: Midlands UK

Re: use fields without a dataprovider attached

Postby pbakker » Thu Sep 25, 2008 5:50 pm

A dataprovider is not an elementName (allthough is you gave them the exact same name they will match).

So vField, holding a dataprovider name, can't be used to reference an element using elements[vField], because vfield should be the elementName.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: use fields without a dataprovider attached

Postby grahamg » Thu Sep 25, 2008 5:58 pm

Thanks for response Paul.

Are you able to suggest what the code should be to get the FieldName & Data pairs? I've tried so many code variations this afternoon that can't think how to do it.

Many thanks
Graham Greensall
Worxinfo Ltd
www.worxinfo.com
grahamg
 
Posts: 752
Joined: Fri Oct 03, 2003 3:15 pm
Location: Midlands UK

Re: use fields without a dataprovider attached

Postby pbakker » Thu Sep 25, 2008 6:03 pm

If you're trying to store edited data that is not saved yet, you can look at the functions under the databaseManager that allow you to get all unsaved data.

If you want to get the data from the fields, you can loop though the elements, check if they are a field, then get the dataprovider and with that the current value.

If you want the data of the current record, just get the record from the foundset.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Next

Return to How To

Who is online

Users browsing this forum: No registered users and 9 guests