Search code examples
xmlodooodoo-15

set Country code and mobile number from contact odoo website


ODOO 15 In contact backend form view we have phone and in contact configuration we have country code as well but in XML I have 2 input tag, I want to save country code and phone number, I had successful done that and is passed to backend as well but now I want is

in my 1st input tag there should be default value which will +91 and in second there should be 10 digit number and when I input value the value should start from 9 not from 0 start value for a number cannot be 0. below is my code:

<div class="row mb-3">
    <label for="mobile" class="col-sm-4 col-form-label col-form-label-sm">Mobile Number
    </label>
    <div class="col-sm-8 mobile">
        <input type="text" class="form-control form-control-sm custom_class"
        name="country_code" id="country_code" maxlength="4" size="4" t-att-value="country_code or +91" autocomplete="off"/>
        <input type="tel" minlength="10" maxlength="10" class="form-control form-control-sm custom_class" id="mobile_number" autocomplete="off"
        name="mobile_number" t-att-value="mobile_numer" pattern="^[0-9]{10}$"/>
    </div>
</div>

my code is accepting 10 digit but i can start from 0 also i cannot set +91 in the code please let me know where i am doing it wrong thanks


Solution

  • First of all if you want to save the whole phone number as a single field, you need to write the JS and implement its return as a single field, or do that in Python part. If you just want not to have 0 at the beginning of a second field, change your pattern to this pattern="^[1-9]{1}[0-9]{9}$".