Note that there are some explanatory texts on larger screens.

plurals
  1. POBlackberry: validate modal Dialog input, do not allow to Save/Ok
    primarykey
    data
    text
    <p>Hello fellow Blackberry developers,</p> <p>please advise me how to validate data entered by user into two BasicEditField's (the myName should be longre than 2 characters; the myFloat should be > 10.0) and:</p> <ol> <li>Mark the BasicEditField containing wrong data red</li> <li>Prevent user from clicking the "Save" (or "OK") button</li> <li>Anything else if above actions are not possible with Blackberry?</li> </ol> <p>Below is my very simple test case. It is a complete code src\mypackage\MyApp.java and will run instantly if you paste it into JDE or Eclipse:</p> <p><img src="https://i.stack.imgur.com/4CV1f.png" alt="screenshot"></p> <pre><code>package mypackage; import net.rim.device.api.system.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.ui.decor.*; public class MyApp extends UiApplication { public static void main(String args[]) { MyApp myApp = new MyEdit(); myApp.enterEventDispatcher(); } public MyApp() { pushScreen(new MyScreen()); } } class MyScreen extends MainScreen { MenuItem myItem = new MenuItem("Show my dialog", 0, 0) { public void run() { String[] buttons = { "Save", "Cancel" }; Dialog dialog = new Dialog("My dialog", buttons, null, 0, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION)); EditField myNameField = new EditField("Name (must be &gt; 2 chars): ", "", TextField.DEFAULT_MAXCHARS, EditField.NO_NEWLINE); dialog.add(myNameField); BasicEditField myFloatField = new BasicEditField("Number: (must be &gt; 10.0)", "", 5, EditField.FILTER_REAL_NUMERIC | EditField.EDITABLE); dialog.add(myFloatField); if (dialog.doModal() == 0) { String myName = myNameField.getText(); float myFloat = 0.0f; try { myFloat = Float.parseFloat(myFloatField.getText()); } catch (NumberFormatException e) { } Status.show("Name: " + myName + ", Number: " + myFloat); } } }; public MyScreen() { setTitle(new LabelField("How to validate input?")); addMenuItem(myItem); } } </code></pre> <p>Before asking this question, I have looked at <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/text/TextFilter.html" rel="nofollow noreferrer">TextFilter</a> and <a href="http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/Field.html#isDataValid%28%29" rel="nofollow noreferrer">Field.isDataValid()</a> but I'm still unsure how to validate user input in Blackberry (vs. I have a pretty clear picture on how to validate user input in a web script with a web form - with jQuery/PHP/Perl/whatever)</p> <p>Thank you! Alex</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload