Form.setSaveOnEnter() is not calling save() as being said.

Hello.

Actually I can’t understand what method is being called if I use

	form.setSaveOnEnter(true);

None of the below methods are being called

		DataSource dataSource = new DataSource();
		dataSource.setClientOnly(true);
		DataSourceTextField dsField = new DataSourceTextField("Field");  
		dataSource.setFields(dsField);  

		final DynamicForm form = new DynamicForm() {
			@Override
			public void submit() {
				System.out.println("sublit");
			}
			@Override
			public void submit(DSCallback callback) {
				System.out.println("sublit");
			}
			
			@Override
			public void submit(DSCallback callback, DSRequest requestProperties) {
				System.out.println("sublit");
			}
			@Override
			public void saveData() {
				System.out.println("sublit");
			}
			@Override
			public void saveData(DSCallback callback) {
				System.out.println("sublit");
			}
			
			@Override
			public void saveData(DSCallback callback,
					DSRequest requestProperties) {
				System.out.println("sublit");
			}
			@Override
			public void submitForm() {
				System.out.println("sublit");
			}
		};
		form.setDataSource(dataSource);
		form.setSaveOnEnter(true);

		VLayout vLayout = new VLayout();  
		vLayout.setMembersMargin(10);  
		vLayout.addMember(form);  

		vLayout.draw();

P.S: the save is actually being done to the datasource…

Just a typo in the topic’s title, it should be submit(), not save():

“Form.setSaveOnEnter() is not calling submit() as being said.”

Hi Isomorphic,

I’m having the same problem as mihai007.
I have following code in an anonymous subclass of DynamicForm with setSaveOnEnter(true) and setCanSubmit(false).
If I use a Button with a ClickEvent-Callback to save(), my @Override method is accessed (all the methods have breakpoints). On ENTER, no breakpoint is hit. How can I interfere in the save-process of ENTER in order to add a DSCallback handler?

@Override
public void saveData() {
	super.saveData();
}
@Override
public void saveData(DSCallback callback) {
	super.saveData(callback);
}

@Override
public void submit() {
	super.submit();
}

Thanks,
Blama

This is the way I have always done it & it works in 3.0:

    // configure the form for enter-key autosubmission
    form.setSaveOnEnter (true);
    form.addSubmitValuesHandler (new SubmitValuesHandler () {
      public void onSubmitValues (final SubmitValuesEvent submitValuesEvent) {
        executeDefaultAction ();
      }
    });

I don’t remember why I started doing it this way.
Maybe the docs used to say to do it this way, or maybe I saw it somewhere.
Maybe this is enough to get you going for now…

Hi shortpasta,

thanks a lot. Exactly what I was looking for.

I now do:

final IButton newBtn = new IButton("Add:", new ClickHandler() {
	@Override
	public void onClick(ClickEvent event) {
		newForm.saveData();
	}
});

and

final DynamicForm newForm = new DynamicForm() {
	@Override
	public void saveData() {
		super.saveData(new DSCallback() {
			@Override
			public void execute(DSResponse response, Object rawData, DSRequest request) {
				if (Helper.oneRow(response)) {
			clearValue(getDataSource().getPrimaryKeyFieldName());
				}
			}
		});
	}

	{
		setDataSource(telefonDS);
		setNumCols(6);
		setSaveOnEnter(true);
		setCanSubmit(false);
		addSubmitValuesHandler(new SubmitValuesHandler() {
			public void onSubmitValues(final SubmitValuesEvent submitValuesEvent) {
				saveData();
			}
		});
...

Destroy the Form in the pop up window after setSaveOnEnter(true);

I have a add button in my ToolsStrip. When clicked on add button there pop s up a dynamic form window, after fetching the data and enter is clicked the data in my form gets saved (data is seen in the background grid). But the Dynamic Form in the pop up window does not gets destroyed.

Is there any handler/any way to destroy the window once data is being saved by clicking enter ?

Thanks in advance.

Hi GSel,

without testing: Try something like:

yourForm.setSaveOnEnter(true);
yourForm.setCanSubmit(false);
yourForm.addSubmitValuesHandler(new SubmitValuesHandler() {
	public void onSubmitValues(final SubmitValuesEvent submitValuesEvent) {
		yourForm.saveData();
		//Check for success
		yourWindow.destroy();
	}
});

Not sure about the first two lines. Read the docs of these and try.

Best regards,
Blama

Hi Blama,

Thanks for your reply, I tried your code. I dont know why but addSubmitValuesHandler is not triggered at all. The form does not gets destroyed.

But there should be a submit event triggered when we setsaveonenter is true. And if its overridden then we can destroy the pop up window after the data is saved. Some where I am missing it .. :frowning:

Maybe somebody is calling a method like Canvas.addKeyPressHandler () to intercept the Enter key.
Then after receiving the event, they are calling KeyPressEvent.cancel () which might prevent the Enter key from reaching the form… Just a guess.

But FYI, the sample I posted earlier has always worked for me, and now I am using SmartGWT 4.0 from 2013-11-30, and it’s working with that build as well.