mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add phone format and validation in payments.
This commit is contained in:
parent
0af6c4b0b6
commit
1050447eed
5 changed files with 44 additions and 30 deletions
|
@ -268,7 +268,7 @@ AddContactBox::AddContactBox(
|
|||
this,
|
||||
st::defaultInputField,
|
||||
tr::lng_contact_phone(),
|
||||
ExtractPhonePrefix(session->user()->phone()),
|
||||
Ui::ExtractPhonePrefix(session->user()->phone()),
|
||||
phone)
|
||||
, _invertOrder(langFirstNameGoesSecond()) {
|
||||
if (!phone.isEmpty()) {
|
||||
|
|
|
@ -46,12 +46,24 @@ PhoneWidget::PhoneWidget(
|
|||
, _code(this, st::introCountryCode)
|
||||
, _phone(this, st::introPhone)
|
||||
, _checkRequestTimer([=] { checkRequest(); }) {
|
||||
connect(_phone, SIGNAL(voidBackspace(QKeyEvent*)), _code, SLOT(startErasing(QKeyEvent*)));
|
||||
connect(_country, SIGNAL(codeChanged(const QString &)), _code, SLOT(codeSelected(const QString &)));
|
||||
connect(_code, SIGNAL(codeChanged(const QString &)), _country, SLOT(onChooseCode(const QString &)));
|
||||
connect(_code, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
|
||||
_phone->frontBackspaceEvent(
|
||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||
_code->startErasing(e);
|
||||
}, _code->lifetime());
|
||||
|
||||
connect(_country, &CountryInput::codeChanged, [=](const QString &code) {
|
||||
_code->codeSelected(code);
|
||||
});
|
||||
_code->codeChanged(
|
||||
) | rpl::start_with_next([=](const QString &code) {
|
||||
_country->onChooseCode(code);
|
||||
_phone->chooseCode(code);
|
||||
}, _code->lifetime());
|
||||
connect(_country, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &)));
|
||||
connect(_code, SIGNAL(addedToNumber(const QString &)), _phone, SLOT(addedToNumber(const QString &)));
|
||||
_code->addedToNumber(
|
||||
) | rpl::start_with_next([=](const QString &added) {
|
||||
_phone->addedToNumber(added);
|
||||
}, _phone->lifetime());
|
||||
connect(_phone, &Ui::PhonePartInput::changed, [=] { phoneChanged(); });
|
||||
connect(_code, &Ui::CountryCodeInput::changed, [=] { phoneChanged(); });
|
||||
|
||||
|
|
|
@ -295,7 +295,6 @@ void Form::refreshPaymentMethodDetails() {
|
|||
const auto &entered = _paymentMethod.newCredentials;
|
||||
_paymentMethod.ui.title = entered ? entered.title : saved.title;
|
||||
_paymentMethod.ui.ready = entered || saved;
|
||||
_paymentMethod.ui.native.defaultPhone = defaultPhone();
|
||||
_paymentMethod.ui.native.defaultCountry = defaultCountry();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue