Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

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

    Hello.

    Actually I can't understand what method is being called if I use
    Code:
    	form.setSaveOnEnter(true);
    None of the below methods are being called
    Code:
    		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...

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

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

    Comment


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

      Code:
      @Override
      public void saveData() {
      	super.saveData();
      }
      @Override
      public void saveData(DSCallback callback) {
      	super.saveData(callback);
      }
      
      @Override
      public void submit() {
      	super.submit();
      }
      Thanks,
      Blama

      Comment


        #4
        This is the way I have always done it & it works in 3.0:
        Code:
            // 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...

        Comment


          #5
          Hi shortpasta,

          thanks a lot. Exactly what I was looking for.

          I now do:

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

          Code:
          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();
          			}
          		});
          ...

          Comment


            #6
            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.

            Comment


              #7
              Hi GSel,

              without testing: Try something like:
              Code:
              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

              Comment


                #8
                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 .. :(

                Comment


                  #9
                  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.

                  Comment

                  Working...
                  X