I have created a user login Dialog Box in MFC, which have two edit fields, for username & password respectively. I need to restrict/disable user from typing "space" & a few "special characters" in Login/Password Edit Box fields. Please help me with this. Thank you.
EDIT: I'm validating the Username & Password with my SQLite database. Everything is working fine. Additional requirement is to restrict user from typing spaces in the edit field.
Please explain with some simple example. Thank you.
You need to subclass(Inherit) the CEdit control of MFC and override PreTranslateMessage and handle WM_CHAR message and filter the characters there
BOOL CMyEditBox::PreTranslateMessage(MSG* pMsg)
{
int nTextLength = this->GetWindowTextLength();
if(pMsg->message==WM_CHAR)
{
// Ignoring 0 to 9
if( ( pMsg->wParam >= '0' && pMsg->wParam <= '9' ) )
{
return true;
}
}
return CEdit::PreTranslateMessage(pMsg);
}
Handle the edit-control change in EN_CHANGE notification message.
Check http://www.flounder.com/validating_edit_control.htm.
It has an explanation plus sample code
EDIT
By the way, I'm not sure that "live validation" for a password field is a good idea. I think "lazy validation" is a better solution here.
As per above answer, this works fine but you can also override CEdit with ASCII values,(in this case we used HEX values followed by '\x')
BOOL TestDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_CHAR)
{
if( ( pMsg->wParam >= '\x20' && pMsg->wParam <= '\x2D'))
{
return true;
}
}
return CEdit::PreTranslateMessage(pMsg);
}
Related
I want to set the value of a simple text field based on the state of another field in a previous page of a form. I am selecting a hosting provider of 'aws' and later in the form, I am asking for the user name.
For aws hosting, I want to force ec2-user to be shown in the text box, so I am using the filter of
add_filter( 'gform_pre_render_4', 'populate_deployment_user' );
function populate_deployment_user( $form )
{
$hosting_provider = rgpost('input_23');
if (strcmp($hosting_provider, "aws") == 0)
{
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 42) {
$field->text = "ec2-user";
}
}
}
}
but the $field->text is not correct. I can't use the gform_field_value_$field_name as that's only called at the start of the form, and not after my other field 23 has been selected.
I'm a newbie in forms, JS and PHP, so floundering somewhat, although I've tried for a couple of days to get a solution.
Solution is to set
$field->defaultValue = "ec2-user";
In Angular 4, I want to check for the current url and if it is equal to "/login" I need to submit a specific form. Here is the code:
let responseString=this.router.url;
console.log(responseString);
if (responseString.match("/login")==null)
this.submitForm();
The above code does not submit the form in all cases. There is something wrong with the if condition I guess.
Any clues?
For simple string-to-string equality, you can use the === operator.
For a more flexible solution I would do
reponseString.includes(“login”)
This way you’re not stuck to the format of the url. It can be a bit more flexible.
use below code for reference
if ( this.loginForm.value['username'] === this.username && this.loginForm.value['password'] === this.password) {
alert(' login successfully : ' + JSON.stringify(this.loginForm.value));
} else {
alert(' enter valid username and password ');
}
I have a custom form where, in a subtab, I have a dropdown that I need to find out the selected value on the client side after the user selects to perform some validation. I created the script and tied it to the on change event of the dropdown. I cannot seem to find the code to get the selected value on the client side. I have found code to read the value on the server side from a submit event. I need this on the client side on change. I am going to use the ID to look up a record and check a value on that record and if applicable popup a warning to the user. Either SS1 or SS2 is good, whatever would be better I have both available. Any help with this would be great. thanks
In a client script, you can use nlapiGetFieldValue() to retrieve the results.
function fieldchanged(type, name, linenum) {
if(name == 'dropdownid') {
var value = nlapiGetFieldValue('dropdownid');
alert(value);
}
}
OK the nlapiGetFieldValue, did not do the trick, what did was the following
function ValidateField( type, field, linenum ) {
if ( field === 'recordid' ) {
var vendorid = nlapiGetCurrentLineItemValue(type,field,linenum);
var vendorRecord = nlapiLoadRecord('vendor',vendorid);
}
return true;
}
thanks for your help
In the application I'm building I have Tabs and a list in for each Tab. the behavior I want is when I press the Left/Right Nav Key the selected Tab will change. when I press the Up/Down Nav Key the List will change selection index.
I used LWUIT GUI builder to generate StateMachine/StateMachineBase class.
I've been trying to fix this all day. please help.
Pheromix's answer is correct but he didn't account for the UIBuilder. To override the Form creation in the UIBuilder override the method:
protected Component createComponentInstance(String componentType, Class cls) {
if(cls == com.sun.lwuit.Form.class) {
return new MyFormSubclass();
}
return super.createComponentInstance(componentType, cls);
}
There is an option to override the Tab selection behavior but to get the most accurate behavior this might be the best approach.
Why do you complicate your life ? Just use keyReleased method implementation in your class. Make a test :
if (display.getGameAction(keyCode) == Display.GAME_LEFT || display.getGameAction(keyCode) == Display.GAME_RIGHT)
{
if (tab.getSelectedIndex == 0)
tab.setSelectedIndex(1);
else
tab.setSelectedIndex(0);
}
else if (display.getGameAction(keyCode) == Display.GAME_UP || display.getGameAction(keyCode) == Display.GAME_DOWN)
{
if (list.hasFocus())
super.keyReleased(keyCode);
}
What does def edit = {} contain by default? You see, I was following a book but it turns out to be using an older version that's why some of the code don't work. I have this piece of code:
def edit= {
def user = User.get(params.id)
if (session?.user?.id == null){
flash.message = "You have to login first before editting your stuff."
redirect(action:'login')
return
}else if(session?.user?.id != params.id) {
flash.message = "You can only edit yourself."
redirect(action:list)
return
}else{
//What should I put here?
}
}
It's already functional. If the user clicks on edit without logging in, then he's redirected to a login page. Otherwise, if he did login, then he's only allowed to edit himself. What should I put on the "else" clause? It should already should already allow the user to edit his stuff, but I don't really know how to implement what I want. :(
It would be great if someone could share the default edit snippet.
I'm a bit new to all these, so go easy on me.
If you're talking about Grails, back up your UserController and try grails generate-controller - it will give you the complete text of default actions.
I also suggest that you look through scaffolding chapter - it's a great point to start.
the default edit action should look like this (pseudo-code, it depends on the actual domain class you create the code upon):
def edit = {
redirect(action: "show", id: params.id)
return true
def <domain>Instance = <DomainClass>.get(params.id)
if (!<domain>Instance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: '<DomainClass>.label', default: '<DomainClass>'), params.id])}"
redirect(action: "list")
}
else {
return [<domain>Instance: <domain>Instance]
}
}
btw: most of the time you don't have to do the security checks by programming these explicitly in the controller code, check out the Grails Spring Security Plugin for that purpose.