use fields without a dataprovider attached

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:
elements.fieldname.selectAll();
application.output(elements.fieldname.getSelectedText());
  1. attach the method to the onFocusLost event
  2. 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

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)

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…

What’s the difference between this:

elements.fieldname.selectAll();
application.output(elements.fieldname.getSelectedText());

And this?

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:

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

but I receive a “java.lang.NullPointerException”(?!?) error :cry:

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:
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.

It seems that replaceSelectedText() only works with fields WITH dataprovider attached :(

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.

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.

It works, thanks.

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

elements.fieldname.replaceSelectedText('');

Because I can use this:

fieldname_calc = '';

exactly.

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???

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

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

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

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

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.

Yep, I think that’s what I should be doing.

Thanks Paul

Graham

Everyone probably knows this by now, but for the newbies out there (like me) …

You can set the dataprovider of a field to a form variable and then the form variable changes when the field does and vise-versa. It’s not as intuitive as elements.myDetachedField.text = “blah”, but it works well. It is probably wise to never leave a dataprovider set at “None”.