Announcement

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

    Datasource fetch causing cursor jump if masksaveliterals are enabled

    1. SmartGWT lgpl-5.0-p20150628
    2. Firefox 39.0
    3. No server side component necessary

    Basic steps to create the applications:

    1, Create a datasource which is pointing to somewhere
    2, Create a timer that periodically fetches the datasource
    3, Create a form
    4, Add a textItem to the form with mask AND setMaskSaveLiterals set to true
    5, Display form
    6, Start application

    Steps to reproduce the bug:

    7, Enter some digits in the textfield (like 55) and wait till the timer starts a database fetch
    8, The cursor is jumping to the end of the textitem

    If I remove either the automatic fetch OR the setMaskSaveLiterals() option then cursor does not move in case of timer action is executed.

    public class SmartGWTTextItem implements EntryPoint {

    CountryDS dataSource = CountryDS.getInstance();

    /**
    * This is the entry point method.
    */
    public void onModuleLoad() {

    Timer t = new Timer() {
    @Override
    public void run() {
    updateMethod();
    }
    };

    t.scheduleRepeating(5000);

    DynamicForm form = new DynamicForm();
    form.setWidth(400);

    TextItem dateField = new TextItem("date", "My custom date");
    dateField.setMask("##-##-####");
    dateField.setMaskSaveLiterals(true);

    form.setFields(dateField);
    form.draw();
    }

    private void updateMethod(){
    dataSource.fetchData(new Criteria(), new DSCallback() {

    @Override
    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
    // do nothing
    }
    });
    }

    private static class CountryDS extends DataSource {
    // The DataSource would normally be defined external to any classes that use it.

    private static CountryDS instance = null;

    public static CountryDS getInstance() {
    if (instance == null) {
    instance = new CountryDS("countryDS_JSON");
    }
    return instance;
    }

    public CountryDS(String id) {
    setID(id);
    setDataFormat(DSDataFormat.JSON);
    DataSourceField countryCodeField = new DataSourceField("countryCode", FieldType.TEXT, "Code");
    DataSourceField countryNameField = new DataSourceField("countryName", FieldType.TEXT, "Country");
    DataSourceField capitalField = new DataSourceField("capital", FieldType.TEXT, "Capital");
    setFields(countryCodeField, countryNameField, capitalField);
    setDataURL("ds/countryData.json");
    }

    }


    }

    #2
    DataSources fetches block the UI by default, which means focus is moved away from the field and back. Rather than worry about this moving the input point, for a periodic fetch you almost certainly want to avoid blocking the UI at all. Use showPrompt:false to do so.

    Comment


      #3
      Thank you very much for your quick response. So the reason is something i suspected.

      My question is: could you please provide me an URL to the javadoc to which component i should set showPrompt? Is it the DataSource?

      I think my issue is related to this previous one:

      http://forums.smartclient.com/showthread.php?t=25866
      Last edited by zsolt.sandor; 9 Jul 2015, 11:11. Reason: found another issue which is quite like mine...

      Comment


        #4
        This is how i solved the problem, however i think this is not a "proper" solution but a workaround...

        private void updateMethod(){

        DSRequest request = new DSRequest();
        request.setShowPrompt(false);

        dataSource.fetchData(new Criteria(), new DSCallback() {

        @Override
        public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
        // do nothing
        }
        }, request);

        }

        Comment

        Working...
        X