vue2-datepicker icon indicating copy to clipboard operation
vue2-datepicker copied to clipboard

Append datepicker to another element != body

Open alfredarcifa opened this issue 5 years ago • 7 comments

In the props there's only "Append to body" flag. There isn't any : appent to props for config where I can associate a class or an id.

Will scheduled for upcoming releases?

alfredarcifa avatar Apr 30 '19 20:04 alfredarcifa

OK, It's a good feature. It will be placed in the next refactoring version when vue3.0 is released.

mengxiong10 avatar May 07 '19 08:05 mengxiong10

@mengxiong10 +! Need to specify which element do I insert it in. How can I insert it in custom element manually now, when there is no such feature?

iatroshchenko avatar Jan 28 '20 08:01 iatroshchenko

Use the ref to append to custome element, and use the popup-style to control the position.

    <div>
      <date-picker
        ref="datepicker"
        v-model="value1"
        :popup-style="{ left: 0, top: '100%' }"
        placeholder="Select date"
      ></date-picker>
      <div ref="target" :style="{ position: 'relative' }">target</div>
    </div>
  mounted() {
    const el = this.$refs.datepicker.$refs.popup.$el;
    this.$refs.target.appendChild(el);
  },

mengxiong10 avatar Jan 31 '20 11:01 mengxiong10

Hello, I have a related question @mengxiong10, what if I need to append the datepicker inside a specific div instead of body, but position relative to an input inside that div?, something like the container's jquery datepicker property.

I really appreciate any help. Thank you.

jdcifuentes avatar Aug 25 '20 00:08 jdcifuentes

When you appent the popup inside a specific element, then

  1. If you want the position of the popup element to be relative to the specific element. You should set the left and top of popup-style.
<template>
  <div id="app">
    <date-picker ref="datepicker" v-model="value" :popup-style="{ top: '100%', left: '0px' }"></date-picker>
    <div
      ref="target"
      :style="{ position: 'relative', width: '300px', height: '30px', border: '1px solid blue', marginTop: '50px' }"
    ></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: null
    };
  },
  mounted() {
    const el = this.$refs.datepicker.$refs.popup.$el;
    this.$refs.target.appendChild(el);
  }
};
</script>


  1. If you want the position of the popup element to be relative to the original input element. You should set popup-style={ position: 'fixed' }.

<template>
  <div id="app">
    <date-picker ref="datepicker" v-model="value" :popup-style="{ position: 'fixed' }"></date-picker>
    <div
      ref="target"
      :style="{ position: 'reletive', width: '300px', height: '30px', border: '1px solid blue', marginTop: '50px' }"
    ></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: null
    };
  },
  mounted() {
    const el = this.$refs.datepicker.$refs.popup.$el;
    this.$refs.target.appendChild(el);
  }
};
</script>

mengxiong10 avatar Aug 25 '20 09:08 mengxiong10

Thank you.

jdcifuentes avatar Sep 07 '20 16:09 jdcifuentes

@mengxiong10 Thank you, you are so handsome

phamvanhiepvn avatar Mar 09 '22 07:03 phamvanhiepvn