iOs has a numeric keypad UIKeyboardTypeNumbersAndPunctuation , but this cannot be called from HTML ( https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html )
since there is no punctuation on the tel keyboard, you need to create it yourself. Since custom ios8 keyboards are available. Or, if you just need punctuation, you can add a button ( How to add the Finish button to a numpad keyboard in iOS ) to the numeric keypad that appears when you specify an input field using type="number" pattern="[0-9]*" .
For this: objective-c code.
-(void)keyboardWillHide:(NSNotification *)note { [self.donekeyBoardBtn removeFromSuperview]; [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: @"document.activeElement.blur()"]]; } - (void)keyboardWillShow:(NSNotification *)note { [UIView setAnimationsEnabled:NO]; // create custom button //UIKeyboardTypeNumberPadin //type="number" pattern="[0-9]*" UIButton *extryB= [UIButton buttonWithType:UIButtonTypeRoundedRect]; extryB.frame = CGRectMake(0, self.view.frame.size.height+150, 100, 50); extryB.backgroundColor = [UIColor colorWithRed:204.0f/255.0f green:210.0f/255.0f blue:217.0f/255.0f alpha:1.0f]; extryB.adjustsImageWhenHighlighted = NO; extryB.titleLabel.font = [UIFont systemFontOfSize:14.0]; [extryB setTitle:@"," forState:UIControlStateNormal]; [extryB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [extryB addTarget:self action:@selector(extryBpressed) forControlEvents:UIControlEventTouchUpInside]; self.donekeyBoardBtn = extryB; // locate keyboard view UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; UIView* keyboard; for(int i=0; i<[tempWindow.subviews count]; i++) { keyboard = [tempWindow.subviews objectAtIndex:i]; // keyboard view found; add the custom button to it if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES) { for(int i = 0 ; i < [keyboard.subviews count] ; i++) { UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i]; if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) { UIButton* donebtn = (UIButton*)[hostkeyboard viewWithTag:67123]; if (donebtn == nil){ //to avoid adding again and again as per my requirement (previous and next button on keyboard) if([[self printKeyboardType] isEqualToString: @"UIKeyboardTypePhonePad"]){ [keyboard addSubview:extryB]; } } } } } //[keyboard addSubview:extryB]; } [UIView setAnimationsEnabled:YES]; // animate [UIView animateWithDuration:0.5 animations:^{ extryB.frame = CGRectMake(0, self.view.frame.size.height-50, 100, 50); }]; } -(NSString*)printKeyboardType { NSString* strKeyboardType = @""; switch (self.textDocumentProxy.keyboardType) { case UIKeyboardTypeAlphabet: strKeyboardType = @"UIKeyboardTypeAlphabet"; break; case UIKeyboardTypeDecimalPad: strKeyboardType = @"UIKeyboardTypeAlphabet"; break; case UIKeyboardTypeDefault: strKeyboardType = @"UIKeyboardTypeDefault"; break; case UIKeyboardTypeEmailAddress: strKeyboardType = @"UIKeyboardTypeEmailAddress"; break; case UIKeyboardTypeTwitter: strKeyboardType = @"UIKeyboardTypeTwitter"; break; case UIKeyboardTypeNamePhonePad: strKeyboardType = @"UIKeyboardTypeNamePhonePad"; break; case UIKeyboardTypeNumberPad: strKeyboardType = @"UIKeyboardTypeNumberPad"; break; case UIKeyboardTypeNumbersAndPunctuation: strKeyboardType = @"UIKeyboardTypeNumbersAndPunctuation"; break; case UIKeyboardTypePhonePad: strKeyboardType = @"UIKeyboardTypePhonePad"; break; case UIKeyboardTypeURL: strKeyboardType = @"UIKeyboardTypeURL"; break; case UIKeyboardTypeWebSearch: strKeyboardType = @"UIKeyboardTypeWebSearch"; break; default: strKeyboardType = @"UNKNOWN"; break; } NSLog(@"self.textDocumentProxy.keyboardType=%@", strKeyboardType); return strKeyboardType; }
Then you must add a method that can be accessed widely in your JS code.
simulateKeyPress: function(k) { var press = jQuery.Event("keypress"); press.which = k;
Dominik Feininger Jun 29. '15 at 15:11 2015-06-29 15:11
source share