2

I have a Vue input number component which accepts precision upto five decimal points. Its all fine except it shows the default value 0.000000 which is kinda boring to look at because this field is optional. I am using el-input-number component from the element-ui. Is there any tweak to remove the boring default value of 0.000000 ?

<span class="custom-label">
Optional Multiplier Amount
</span>
<el-input-number
   :controls="false"
   v-model="form.multiplier_amount"
   :size="size"
   :step="0.1"
   :precision="5"
   class="optional-multiplier"
   />

data(){
 return{
  form: {
    multiplier_amount: null
        }
       }
      }

enter image description here

5
  • if placeholder="..." doesn't work add a ref to access the element (or traverse through it to the input) to change the placeholder Commented Apr 18, 2022 at 12:46
  • @LawrenceCherone thats not because of placeholder Commented Apr 18, 2022 at 12:47
  • You could maybe have multiplier_amount: 0.00000 || '' in your data()/computed(). Commented Apr 18, 2022 at 12:47
  • oh right so form.multiplier_amount = 0.00000? then its obvious, remove the value :/ Commented Apr 18, 2022 at 12:48
  • @kissu my data value is null, I have updated my question. Commented Apr 18, 2022 at 12:52

1 Answer 1

2

Just set it as undefined:

new Vue({
  el: "#demo",
  data(){
    return{
      form: {
        multiplier_amount: undefined
      },
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<div id="demo">
  <span class="custom-label">
    Optional Multiplier Amount
  </span>
  <el-input-number
    :controls="false"
    v-model="form.multiplier_amount"
    :step="0.1"
    class="optional-multiplier"
    :precision="5"
  />
</div>

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer but still if you run your example it will have a default value of 0, which is exactly what I wanted to remove. 0.00000 or 0 is same thing, I just need to force users to have max 5 points. So it still doesn't answer my question.
@gitam gadtaula hey mate, take a look again I corrected my answer
Thanks it works. By the way is it possible that having the default value as undefined may bring unprecedented complication in the future ? What might be the effect of using undefined over null ?
In your context no worries I think :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.