Add phone format and validation in payments.

This commit is contained in:
John Preston
2021-03-29 18:56:26 +04:00
parent 0af6c4b0b6
commit 1050447eed
5 changed files with 44 additions and 30 deletions
+8 -8
View File
@@ -30,8 +30,7 @@ constexpr auto kMaxPhoneCodeLength = 4;
CountryCodeInput::CountryCodeInput(
QWidget *parent,
const style::InputField &st)
: MaskedInputField(parent, st)
, _nosignal(false) {
: MaskedInputField(parent, st) {
}
void CountryCodeInput::startErasing(QKeyEvent *e) {
@@ -91,14 +90,15 @@ void CountryCodeInput::correctValue(
setCorrectedText(now, nowCursor, newText, newPos);
if (!_nosignal && was != newText) {
codeChanged(newText.mid(1));
_codeChanged.fire(newText.mid(1));
}
if (!addToNumber.isEmpty()) {
addedToNumber(addToNumber);
_addedToNumber.fire_copy(addToNumber);
}
}
PhonePartInput::PhonePartInput(QWidget *parent, const style::InputField &st) : MaskedInputField(parent, st/*, tr::lng_phone_ph(tr::now)*/) {
PhonePartInput::PhonePartInput(QWidget *parent, const style::InputField &st)
: MaskedInputField(parent, st/*, tr::lng_phone_ph(tr::now)*/) {
}
void PhonePartInput::paintAdditionalPlaceholder(Painter &p) {
@@ -119,8 +119,8 @@ void PhonePartInput::paintAdditionalPlaceholder(Painter &p) {
}
void PhonePartInput::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Backspace && getLastText().isEmpty()) {
voidBackspace(e);
if (e->key() == Qt::Key_Backspace && cursorPosition() == 0) {
_frontBackspaceEvent.fire_copy(e);
} else {
MaskedInputField::keyPressEvent(e);
}
@@ -204,7 +204,7 @@ void PhonePartInput::addedToNumber(const QString &added) {
startPlaceholderAnimation();
}
void PhonePartInput::onChooseCode(const QString &code) {
void PhonePartInput::chooseCode(const QString &code) {
_pattern = phoneNumberParse(code);
if (!_pattern.isEmpty() && _pattern.at(0) == code.size()) {
_pattern.pop_front();
+18 -15
View File
@@ -12,18 +12,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
class CountryCodeInput : public MaskedInputField {
Q_OBJECT
public:
CountryCodeInput(QWidget *parent, const style::InputField &st);
public Q_SLOTS:
void startErasing(QKeyEvent *e);
void codeSelected(const QString &code);
Q_SIGNALS:
void codeChanged(const QString &code);
void addedToNumber(const QString &added);
[[nodiscard]] rpl::producer<QString> addedToNumber() const {
return _addedToNumber.events();
}
[[nodiscard]] rpl::producer<QString> codeChanged() const {
return _codeChanged.events();
}
void codeSelected(const QString &code);
protected:
void correctValue(
@@ -33,22 +34,23 @@ protected:
int &nowCursor) override;
private:
bool _nosignal;
bool _nosignal = false;
rpl::event_stream<QString> _addedToNumber;
rpl::event_stream<QString> _codeChanged;
};
class PhonePartInput : public MaskedInputField {
Q_OBJECT
public:
PhonePartInput(QWidget *parent, const style::InputField &st);
public Q_SLOTS:
void addedToNumber(const QString &added);
void onChooseCode(const QString &code);
[[nodiscard]] auto frontBackspaceEvent() const
-> rpl::producer<not_null<QKeyEvent*>> {
return _frontBackspaceEvent.events();
}
Q_SIGNALS:
void voidBackspace(QKeyEvent *e);
void addedToNumber(const QString &added);
void chooseCode(const QString &code);
protected:
void keyPressEvent(QKeyEvent *e) override;
@@ -63,6 +65,7 @@ protected:
private:
QVector<int> _pattern;
QString _additionalPlaceholder;
rpl::event_stream<not_null<QKeyEvent*>> _frontBackspaceEvent;
};